atcoder#ABC266H. [ABC266Ex] Snuke Panic (2D)
[ABC266Ex] Snuke Panic (2D)
Score : points
Problem Statement
Takahashi is trying to catch many Snuke.
There are some pits in a two-dimensional coordinate plane, 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 coordinates at time , and its size is .
Takahashi is at coordinates at time and can do the following two kinds of moves.
- Move at a speed of at most in the -direction (positive or negative).
- Move at a speed of at most in the positive -direction.
Moving in the negative -direction is not allowed.
He can catch a Snuke appearing from a pit if and only if he is at the coordinates 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
- The triples are distinct.
- 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 0 100
3 2 1 10
5 3 1 1
101
The optimal strategy is as follows.
- Wait at coordinates to catch the first Snuke at time .
- Go to coordinates 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.
2
100 0 1 1
200 1 0 10
10
Moving in the negative -direction is not allowed, so he cannot catch the first Snuke and then the second.
10
797829355 595605750 185676190 353195922
913575467 388876063 395940406 533206504
810900084 201398242 159760440 87027328
889089200 220046203 85488350 325976483
277429832 161055688 73308100 940778720
927999455 429014248 477195779 174616807
673419335 415891345 81019893 286986530
989248231 147792453 417536200 219371588
909664305 22150727 414107912 317441890
988670052 140275628 468278658 67181740
1553741733