#C13810. Ticket Reservation System Simulation

    ID: 43390 Type: Default 1000ms 256MiB

Ticket Reservation System Simulation

Ticket Reservation System Simulation

This problem simulates a ticket reservation system that manages a dynamic customer queue. In this system, customers are added with a specific priority. The customer with the lowest priority value is served first. If two customers have the same priority, the one who was added earlier is served first. Duplicate names are not allowed in the system.

Your task is to implement the system which supports the following commands:

  • ADD: Adds a new customer with the given id, name, priority and number of tickets. Upon a successful addition, output "Customer added successfully.". If a customer with the same name already exists in the queue, output "Error: Customer with the same name is already in the queue.".
  • SERVE: Serves the customer with the highest priority (i.e. the one with the smallest priority value). Print the served customer's details in the format: id name priority number_of_tickets. If there are no customers to serve, output "No customers to serve.".
  • VIEW: Displays the current queue in order of service. If the queue is non-empty, print the list of customers formatted as id name priority number_of_tickets for each customer separated by a semicolon and a space ('; '). If the queue is empty, output "[]".

The commands will be given as input from standard input. Process each command and output the corresponding response to standard output.

inputFormat

The first line contains an integer n denoting the number of commands. Each of the next n lines contains a command. The command can be one of the following formats:

  • ADD id name priority number_of_tickets
  • SERVE
  • VIEW

For the ADD command, id, priority and number_of_tickets are integers, and name is a string (without spaces).

outputFormat

For each command, output the result in a new line as follows:

  • For ADD, output either "Customer added successfully." or "Error: Customer with the same name is already in the queue."
  • For SERVE, if the queue is non-empty, output the served customer details as: id name priority number_of_tickets; otherwise, output "No customers to serve."
  • For VIEW, if the queue is non-empty, output the list of customers (in order) separated by "; ". Each customer is printed as: id name priority number_of_tickets. If the queue is empty, output "[]".
## sample
4
ADD 1 Alice 1 2
ADD 2 Bob 2 1
VIEW
SERVE
Customer added successfully.

Customer added successfully. 1 Alice 1 2; 2 Bob 2 1 1 Alice 1 2

</p>