#FT0000158. Bắt Snuke trên mặt phẳng (Snuke Panic (2D))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bắt Snuke trên mặt phẳng (Snuke Panic (2D))
Snuke Panic (2D)
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi starts at at time . He can move in either -direction with speed at most , but can move in the positive -direction only, at speed at most ; moving downwards is forbidden. Snuke appears at time at and is worth . It can be captured only by being at its exact position at that instant, with negligible capture time. Moving from to is feasible exactly when and . Maximize total reward, possibly catching none. The result may exceed 32 bits.
Input
The first line contains . Each of the next lines gives .
Output
Print the maximum total reward as a 64-bit integer.
Subtasks
- Subtask 1 (20 points): ; , , ; all triples are distinct.
- Subtask 2 (30 points): ; , , ; all triples are distinct.
- Subtask 3 (50 points): ; , , ; all triples are distinct.
Examples
Example 1
Input
3
1 0 0 100
3 2 1 10
5 3 1 1
Output
101
Explanation
Wait at at time 1 to collect reward 100. The second event at at time 3 needs three movement units within two time units and is unreachable. The third event at at time 5 is reachable in four units, giving reward .
Example 2
Input
2
100 0 1 1
200 1 0 10
Output
10
Explanation
Both cannot be caught: going from to would decrease the y-coordinate, which is forbidden. Skipping the first allows catching the second for reward 10.