452. Poison Duration
EasySimulation
Each attack at time t poisons for d seconds, covering [t, t + d − 1]; a new attack resets the timer. Attack times are sorted. Print the total poisoned seconds.
Input format
Line 1: n d Line 2: n attack times
Output format
The total duration.
Example 1
Input
2 2 1 4
Output
4
Example 2
Input
2 2 1 2
Output
3
Constraints
1 ≤ n ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…