No.3424 Shooting Game
Problem Statement
Takumi is playing a shooting game. He can earn a positive score by hitting the targets that appear with bullets from his gun. A total of $N$ targets appear.
Bullets can only be fired at integer seconds. The $i$-th target appears from $L_i-0.1$ seconds to $R_i+0.1$ seconds (inclusive) after the start of the game, and it is considered hit if a bullet is fired at an integer time
$t$ during this period. The score obtained in that case is $P_i$ points.
Each shot from the gun hits one target. Reloading then takes $T$ seconds, and the next bullet can be fired $T$ seconds after the shot.
Note that $T$ seconds is longer than the appearance duration of any target.
Also, a bullet is already loaded at the start of the game.
Output the maximum total score Takumi can obtain.
Constraints
- $1 \leq N \leq 2 \times 10^5$
- $0 \leq L_i < R_i \leq 2 \times 10^5$
- $1 \leq P_i \leq 10^9$
- $\max(R_i - L_i) < T \leq 2 \times 10^5$ $(1 \leq i \leq N)$
- All inputs are integers.
Input
The input is given from standard input in the following format.
$N\ T$ $L_1\ R_1\ P_1$ $L_2\ R_2\ P_2$ ⋮ $L_N\ R_N\ P_N$
Output
Output the maximum total score Takumi can obtain on a single line.
Sample
Sample 1
Input
4 5 0 4 10 5 7 20 6 9 30 10 11 50
Output
90
For example, Takumi can obtain $10+30+50=90$ points in the following way.
- Shoot the $1$-st target at $0$ seconds.
- Shoot the $3$-rd target at $6$ seconds.
- Shoot the $4$-th target at $11$ seconds.
Sample 2
Input
5 2 1 2 1000000000 3 4 1000000000 5 6 1000000000 7 8 1000000000 9 10 1000000000
Output
5000000000
Note that the output may not fit in a 32-bit integer type.
Sample 3
Input
7 8 0 4 10 5 7 20 6 9 30 10 11 50 3 6 50 10 12 70 25 30 100
Output
220
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
まみめ
kidodesu