CF499A.Watching a movie

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have decided to watch the best moments of some movie. There are two buttons on your player:

  1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.
  2. Skip exactly xx minutes of the movie ( xx is some fixed positive integer). If the player is now at the tt -th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t+x)(t+x) .

Initially the movie is turned on in the player on the first minute, and you want to watch exactly nn best moments of the movie, the ii -th best moment starts at the lil_{i} -th minute and ends at the rir_{i} -th minute (more formally, the ii -th best moment consists of minutes: li,li+1,...,ril_{i},l_{i}+1,...,r_{i} ).

Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?

输入格式

The first line contains two space-separated integers nn , xx ( 1<=n<=501<=n<=50 , 1<=x<=1051<=x<=10^{5} ) — the number of the best moments of the movie and the value of xx for the second button.

The following nn lines contain the descriptions of the best moments of the movie, the ii -th line of the description contains two integers separated by a space lil_{i} , rir_{i} ( 1<=li<=ri<=1051<=l_{i}<=r_{i}<=10^{5} ).

It is guaranteed that for all integers ii from 22 to nn the following condition holds: r_{i-1}<l_{i} .

输出格式

Output a single number — the answer to the problem.

输入输出样例

  • 输入#1

    2 3
    5 6
    10 12
    

    输出#1

    6
    
  • 输入#2

    1 1
    1 100000
    

    输出#2

    100000
    

说明/提示

In the first sample, the player was initially standing on the first minute. As the minutes from the 11 -st to the 44 -th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 33 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 44 -th to the 66 -th minute, after that the current time is 77 . Similarly, we again skip 33 minutes and then watch from the 1010 -th to the 1212 -th minute of the movie. In total, we watch 66 minutes of the movie.

In the second sample, the movie is very interesting, so you'll have to watch all 100000100000 minutes of the movie.

首页