#C9666. Priority Order Processing
Priority Order Processing
Priority Order Processing
You are given a series of commands to simulate an order processing system for products, utilizing a priority queue (min-heap). The commands are of two types:
add P
: Add an order with a priority value P.process
: Process an order by removing the one with the smallest priority value from the queue. If the queue is empty, output-1
.
When two orders have the same priority, the order that was added earlier should be processed first. Your task is to simulate this process.
Note: The input will be provided from standard input and the output must 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, either in the format "add P" (where P is an integer priority) or "process".
outputFormat
For every "process" command, output the result on a new line. The result is the smallest priority value available. If the queue is empty when a "process" command is encountered, print -1
.## sample
7
add 5
add 3
process
add 1
process
process
process
3
1
5
-1
</p>