P12244 Stepping on Points

Background

You can switch the language of problem description. ![](https://cdn.luogu.com.cn/upload/image_hosting/96tdfgkh.png)

Description

Today is another school day with $n$ classes. The $i$-th class starts at the beginning of minute $l_i$ and ends at the beginning of minute $r_i$. Little O wants to play basketball during every break between classes. However, the round-trip between the classroom and the playground takes a total of $T$ minutes. Little O will go to play basketball during a break **if and only if** he can return to the classroom without being late for the next class. Otherwise, he stays in the classroom. How many total minutes will Little O spend playing basketball today?

Input Format

- The first line contains two integers $n$ and $T$, representing the number of classes and the round-trip time. - The next $n$ lines each contain two integers $l_i$ and $r_i$, describing the start and end time of the $i$-th class.

Output Format

Output one integer: the total minutes Little O spends playing basketball.

Explanation/Hint

### Sample #1 Explanation - **Break 1** (between classes 1 and 2): Duration = $5 - 2 = 3$ minutes. After spending $2$ minutes on the round-trip, Little O plays for $1$ minute. - **Break 2** (between classes 2 and 3): Duration = $8 - 7 = 1$ minute. The round-trip requires $2$ minutes, so he skips it. Total play time: $1$ minute. ## Constraints - $2 \le n \le 10^5$ - $0 \le T \le 10^8$ - $1 \le l_i \le r_i \le 10^8$ - For $1 \le i \le n-1$: $r_i \le l_{i+1}$ (classes are non-overlapping and ordered chronologically). ### Subtasks - **20%**: $n = 2$ - **20%**: $T = 0$ - **20%**: $T = 1$ - **40%**: No additional constraints