Priority queue · Compiler

Priority queue

Process commands for an initially empty priority queue. ADD inserts an item. TAKE removes the item with the smallest numeric priority. Among items with that priority, remove the one added earliest.

Input
The first line contains q (1 <= q <= 100). Each of the next q lines contains ADD name p or TAKE. Names are distinct words of 1 to 20 lowercase English letters and p is an integer from -100 to 100. There is at least one TAKE.
Output
For each TAKE, print the removed name on its own line. Print EMPTY when there is no item to take.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…