#C9440. Priority Reservation System
Priority Reservation System
Priority Reservation System
This problem simulates a restaurant reservation system where customers are assigned a priority. The system supports the following commands which you will process from standard input:
- add <reservation_id> <priority> – Add a new reservation. Each reservation has a unique ID and an integer priority.
- serve – Serve the reservation with the highest priority. If multiple reservations share the same priority, serve the one added earlier. Print the served reservation ID. If no reservations exist, print
None
. - cancel <reservation_id> – Cancel an existing reservation identified by its reservation ID.
- snapshot – Print a snapshot of all current reservations in the order in which they were added (i.e. ascending insertion order).
You are required to implement the system using a priority queue to determine which reservation to serve next. Note that while serving uses the highest priority (with ties broken by insertion order), the snapshot simply lists all remaining reservations in order of addition.
Note: All input is read from standard input and output should be printed to standard output.
inputFormat
The first line contains an integer n
representing the number of commands. Each of the following n
lines contains a command. The commands can be one of the following:
add <reservation_id> <priority>
serve
cancel <reservation_id>
snapshot
Reservations added with the add
command must be processed accordingly. For the serve
command, output one line containing the served reservation id (or None
if there is none) and for the snapshot
command, output one line with the space‐separated reservation ids in order of their addition.
outputFormat
For each serve
and snapshot
command in the input, print the corresponding result on a separate line as described above.
6
add 1 20
add 2 30
serve
snapshot
add 3 25
serve
2
1
3
</p>