#P12244. 踩点

    ID: 11687 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>模拟洛谷原创O2优化洛谷月赛

踩点

Description

Today is another school day with nn classes. The ii-th class starts at the beginning of minute lil_i and ends at the beginning of minute rir_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 TT 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 nn and TT, representing the number of classes and the round-trip time.
  • The next nn lines each contain two integers lil_i and rir_i, describing the start and end time of the ii-th class.

Output Format

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

3 2
1 2
5 7
8 9
1

Hint

Sample #1 Explanation

  • Break 1 (between classes 1 and 2): Duration = 52=35 - 2 = 3 minutes. After spending 22 minutes on the round-trip, Little O plays for 11 minute.
  • Break 2 (between classes 2 and 3): Duration = 87=18 - 7 = 1 minute. The round-trip requires 22 minutes, so he skips it.
    Total play time: 11 minute.

Constraints

  • 2n1052 \le n \le 10^5
  • 0T1080 \le T \le 10^8
  • 1liri1081 \le l_i \le r_i \le 10^8
  • For 1in11 \le i \le n-1: rili+1r_i \le l_{i+1} (classes are non-overlapping and ordered chronologically).

Subtasks

  • 20%: n=2n = 2
  • 20%: T=0T = 0
  • 20%: T=1T = 1
  • 40%: No additional constraints