Driving Practice
Time limit1sMemory limit1024 MB
For each station where the wizard may appear, find the teleport station that lets the car run out of electricity farthest from the origin, and print it with the charge change.
- Level
Medium7 of 10
- Topics
- Greedy, Prefix sum, Stack
- Solved
- No attempts yet
Problem
Sieun, who holds a license that has never been used on the road, practices driving on a number line. Sieun starts at the origin and always moves in the positive direction. The car uses 1 kWh of electricity for each unit of distance it travels, and moving is the only way it uses electricity. The car starts with no electricity, and a car with no electricity cannot move until it is charged.
There are charging stations, numbered from 0 to , on the number line. Station is at point , and visiting it charges the car by kWh. One of the stations other than station 0 has a mischievous wizard hidden at it. When Sieun arrives at that station, the wizard teleports Sieun to one of the stations that come before it (that is, closer to the origin). Sieun chooses which station to teleport to. Teleporting uses no electricity, and the wizard plays this trick only once.
The car cannot be charged at the station where the wizard plays the trick. After being teleported, Sieun can charge at the stations again. For example, suppose Sieun meets the wizard at station 3 and chooses to teleport to station 1. Then the car can be charged in this order: 0 to 1 to 2 to (no charge at station 3 because of the wizard) to 1 to 2 to 3 to ...
Assume Sieun meets the wizard at each station in turn. Find which station Sieun should choose so that the car runs out of electricity as far from the origin as possible.
Input
The first line contains , the number of charging stations excluding station 0.
Each of the next lines contains the information for station , in order of increasing number from station 0: and , separated by a space.
Output
Print lines in total. On line , print two integers and separated by a space ().
If station cannot be reached without meeting the wizard:
- and are both -1.
Otherwise:
- is the number of the station Sieun should choose when meeting the wizard at station .
- is the change in the electricity stored in the car when Sieun teleports to station and then returns to station .
- If several values of satisfy the condition, print the largest one.
Constraints
- ()
- The car can be charged with an unlimited amount of electricity.
- All input numbers are integers.