Tall Poppies
Will is a Florist who owns a flower bed of poppies. Every day, all of Will's poppies will grow exactly centimetres taller.
As part of managing a healthy flower bed, Will does one of two things:
- Harvest the tallest poppy to sell at his shop
- Plant a poppy of height cm
Will would like to know the height of the poppies that he harvests so that he can set the correct selling price. Can you help him?
Input
Input will start with three space-separated integers , and , the number of centimetres a poppy grows in a day, the number of poppies in the flower bed at day 0, and the number of events we'll be observing. The next line will contain space-separated integers, the heights of the poppies at start of day 0.
lines will follow. Each of these lines will start with two space-separated integers, and . is the day on which this event is occuring (You may assume all events are occuring at the start of the day).
- If is 0, then this event is Will harvesting the tallest poppy in his flowerbed, and no more input will follow on this line.
- If is 1, then this event is Will planting a poppy, an additional integer will follow , the height of this individual poppy.
Example Input
1 4 5
5 8 3 6
1 0
1 1 8
2 1 6
4 0
5 0
Here poppies grow at 1cm a day, and Will:
- Has 4 poppies to begin with at day 0, of heights 5, 8, 3 and 6 cm.
- On Day 1 - Will harvests the tallest poppy then plants a poppy of height 8cm
- On Day 2 - Will plants a poppy of height 8cm
- On Day 4 - Will harvests the tallest poppy
- On Day 5 - Will harvests the tallest poppy
Output
If your input contains event lines containing . For each corresponding harvest event, you should print a single integer representing the height of the harvested poppy.
Example Output
9
11
11
- The poppies start off with heights 5, 8, 3, 6.
- At the start of Day 1, we have heights 6, 9, 4, 7 - so Will harvests the 9 height poppy.
- We plant an addition poppy, so new heights are 6, 4, 7, 8
- At the start of Day 2, we have heights 7, 5, 8, 9, and we plant a poppy of height 6
- At the start of Day 4, we have heights 9, 7, 10, 11, 7, and so we harvest the poppy of height 11
- At the start of Day 5, we have heights 10, 8, 11, 8, and so we harvest the poppy of height 11
Constraints
- (Day of an event)
- (Individual poppy heights)
- (Growth per day)
- Harvest events will never occur when the flower bed is empty
Test Set A (50%)
- (Number of initial poppies)
- (Number of events)
Test Set B (50%)
- (Number of initial poppies)
- (Number of events)
Comments