Christmas Gifts
Time limit2sMemory limit512 MB
Process visits in order: depots add gifts to Santa's collection, and each child takes the largest gift currently held.
- Level
Medium4 of 10
- Topics
- Heap, Simulation, Greedy
- Solved
- No attempts yet
Problem
At Christmas, Santa hands out gifts to the children who behaved well. His sleigh is small and cannot carry every gift at once, so he stops at the depots he set up around the world and loads more gifts there. When he meets a good child, he hands over the single most valuable gift he is carrying at that moment.
You are given the depots and the children Santa visits, in order. For each child, print the value of the gift Santa hands over. If he is carrying no gift, print -1.
Input
The first line contains the number of visits . ()
Each of the next lines describes one visit, in order, and starts with an integer . If is 0, Santa meets a child. Otherwise Santa stops at a depot, and the values of the gifts loaded there follow on the same line, separated by spaces. ()
Every gift value is a positive integer smaller than 100,000.
Output
For each line whose is 0, print the value of the gift handed to that child, one per line. Print -1 on that line if Santa has no gift to hand over. At least one line has equal to 0.