#P12244. Ball Game During School Breaks
Ball Game During School Breaks
Ball Game During School Breaks
Today is a school day with (n) lessons. The (i)-th lesson starts at the beginning of minute (l_i) and ends at the beginning of minute (r_i). Between each consecutive lessons, there is a break. Xiao O wants to play ball during every break, but he needs a total of (T) minutes to go to and come back from the playground. In other words, in a break of length (gap = l_{i+1} - r_i), if (gap \ge T), he will spend (gap - T) minutes playing ball; otherwise, he stays in the classroom. Your task is to compute the total minutes Xiao O spends playing ball during the day.
inputFormat
The input begins with a line containing two integers (n) and (T). Each of the following (n) lines contains two integers (l_i) and (r_i) representing the start and end times (in minutes) of the (i)-th lesson.
outputFormat
Output a single integer that denotes the total minutes Xiao O spends playing ball.
sample
3 10
1 50
60 100
110 150
0