← 返回 optiver 的题目列表Real-time Ticket Purchasing System
类型:online_judge
optiver
Description
Design a real-time concert ticket purchasing system. The service publishes available ticket information in multiple packets. You have a wishlist of artists you want to see, the maximum price you're willing to pay, and the minimum number of seats you want to purchase.
Design a program to listen for available tickets and make purchases according to criteria.
Requirements
Received 'AvailableTicket' message format:
Packet 1: Message ID and Artist ID
Packet 2: Message ID and Ticket Price
Packet 3: Message ID and Available Seats
Message IDs are unique for a set of packets and are not reused.
Order of packets for the same message ID is guaranteed, but packets from different messages can be interleaved.
Order response format:
Packet 1: Artist ID
Packet 2: Number of seats to purchase
Write the following interface:
ConcertTickets.__init__(): Initialization method.
ConcertTickets.on_receive_requirements: Takes parameters: artist ID, maximum price, minimum seats.
ConcertTickets.process_packet(int message_id, str data) -> int: Processes the packet, returns order response packet based on criteria. Return 0 if no order.
Example Input
concert = ConcertTickets()
concert.on_receive_requirements(artist_id=1, max_price=100, min_seats=2)
concert.process_packet(message_id=1, data="artist_id:1")
concert.process_packet(message_id=1, data="price:90")
concert.process_packet(message_id=1, data="seats:3")
Constraints
Number of artists and tickets is limited.
Packet order is guaranteed by message ID.
Example
Input
concert.on_receive_requirements(artist_id=1, max_price=100, min_seats=2)
concert.process_packet(message_id=1, data="artist_id:1")
concert.process_packet(message_id=1, data="price:80")
concert.process_packet(message_id=1, data="seats:3")