atcoder#ABC219H. [ABC219H] Candles
[ABC219H] Candles
Score : points
Problem Statement
There are candles on an infinite number line. The -th candle is at the coordinate . At time , it has a length of and is lit. Each minute, the length of a lit candle decreases by . When the length becomes , it burns out, and its length does not change after that. Additionally, the length of an unlit candle does not change.
Takahashi is at the coordinate at time . Each minute, he can move a distance of at most . If there is a candle at his current coordinate, he can put out that candle. (If there are multiple candles there, he can put out all of them.) The time it takes to put out a candle is negligible.
Find the maximum possible total length of the candles remaining at minutes after time , achieved by Takahashi's optimal course of actions.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
-2 10
3 10
12 10
11
The third candle, which is at coordinate , will burn out before Takahashi puts it out, regardless of Takahashi's behavior. For the other two candles, if he goes to coordinate in two minutes to put out the first and then goes to coordinate in five minutes to put out the second, the lengths of those candles will not change after that. The lengths of those candles remaining are and , for a total of , which is the maximum that can be achieved. Thus, print .
5
0 1000000000
0 1000000000
1 1000000000
2 1000000000
3 1000000000
4999999994
Note that two or more candles may occupy the same coordinate and that the answer may not fit into a -bit integer.