atcoder#ABC266D. [ABC266D] Snuke Panic (1D)
[ABC266D] Snuke Panic (1D)
Score : points
Problem Statement
Takahashi is trying to catch many Snuke.
There are five pits at coordinates , , , , and on a number line, connected to Snuke's nest.
Now, Snuke will appear from the pits. It is known that the -th Snuke will appear from the pit at coordinate at time , and its size is .
Takahashi is at coordinate at time and can move on the line at a speed of at most . He can catch a Snuke appearing from a pit if and only if he is at the coordinate of that pit exactly when it appears. The time it takes to catch a Snuke is negligible.
Find the maximum sum of the sizes of Snuke that Takahashi can catch by moving optimally.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
3
1 0 100
3 3 10
5 4 1
101
The optimal strategy is as follows.
- Wait at coordinate to catch the first Snuke at time .
- Go to coordinate to catch the third Snuke at time .
It is impossible to catch both the first and second Snuke, so this is the best he can.
3
1 4 1
2 4 1
3 4 1
0
Takahashi cannot catch any Snuke.
10
1 4 602436426
2 1 623690081
3 3 262703497
4 4 628894325
5 3 450968417
6 1 161735902
7 1 707723857
8 2 802329211
9 0 317063340
10 2 125660016
2978279323