Print Panic
The university printers are broken again and the IT guy is on vacation in the Bahamas, so the staff are asking you, the closest computer science student, to help them fix it.
The printers get a stream of messages over the internet, and there are only certain times when they can print documents. The program needs to decide which print jobs to process at each time. The printers operate on a priority system, as some people need their prints more urgently. The order is Vice-Chancellor, Senior Admin, Admin Staff, Teachers/Lecturers, and then Students. If multiple print jobs have the same priority, the oldest should be printed first.
Input
The first line contains an integer , detailing the number of lines of input following.
The next lines each contain either two integers, or the word "print". In the case of the two integers, the first integer is an id
and the second integer is a priority level
. Higher priorities (larger values of
) should be printed first. ids are guaranteed to be unique.
Output
For each print
command, you need to output the id of the print job which will be processed. This should correspond to the highest priority task currently in the queue. If there are multiple jobs with the same priority, the one which was entered first should be processed. These ids should be separated by newlines.
If print
is inputted when the print queue is empty, output "ERROR" on a line by itself.
Example
Input 1
10
1 2
2 1
print
5 5
3 5
4 2
print
print
print
print
Output 1
1
5
3
4
2
The ID of 1 has a priority 2, which is the highest when that print runs. Next, 5 and 3 both have same priority, so 5 is first, followed by 3. Then, the remaining 2 and 4 have priorities 2 and 1, so 4 is printed first followed by 2.
Input 2
4
1 3
2 5
3 4
print
Output 2
2
ID 2 has a priority 5, which is the highest. Not everything needs to get printed out, the output lines should correspond to the number of print commands.
Input 3
7
5 5
2 3
1 5
print
print
print
print
Output 3
5
1
2
ERROR
1 and 5 both have priority 5, but 5 was added first, so it is printed before. Then id 2 has priority 3 so it is printed after, and finally the queue is empty so ERROR is outputted.
Comments