CF499A.Watching a movie
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have decided to watch the best moments of some movie. There are two buttons on your player:
- 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.
- Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x).
Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the l__i-th minute and ends at the r__i-th minute (more formally, the i-th best moment consists of minutes: l__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?
你决定观看某部电影中最精彩的片段。你的播放器上有两个按钮:
- 观看当前电影的这一分钟。按下此按钮后,你将观看当前这一分钟的电影内容,播放器会自动跳转到电影的下一分钟。
- 跳过电影中恰好 x 分钟(x 是某个固定的正整数)。若播放器当前位于电影的第 t 分钟,则按下此按钮后,播放器将跳转至第 (t + x) 分钟。
初始时,电影从第 1 分钟开始播放,而你想完整观看电影中恰好 n 个最精彩片段;其中第 i 个最精彩片段起始于第 l__i 分钟、结束于第 r__i 分钟(更准确地说,第 i 个最精彩片段包含的分钟为:l__i, l__i + 1, ..., r__i)。
请确定:若要完整观看所有这些最精彩片段,你至少需要观看电影多少分钟?
输入格式
The first line contains two space-separated integers n, x (1 ≤ n ≤ 50, 1 ≤ x ≤ 105) — the number of the best moments of the movie and the value of x for the second button.
The following n lines contain the descriptions of the best moments of the movie, the i-th line of the description contains two integers separated by a space l__i, r__i (1 ≤ l__i ≤ r__i ≤ 105).
It is guaranteed that for all integers i from 2 to n the following condition holds: r__i - 1 < l__i.
第一行包含两个以空格分隔的整数 n、x(1 ≤ n ≤ 50,1 ≤ x ≤ 105)——分别表示电影中最佳时刻的数量以及第二个按钮对应的值 x。
接下来的 n 行描述了电影中的各个最佳时刻,其中第 i 行包含两个以空格分隔的整数 li、ri(1 ≤ li ≤ ri ≤ 105)。
保证对所有从 2 到 n 的整数 i,均满足条件:ri−1 < li。
输出格式
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 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie.
In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
在第一个样例中,玩家初始时站在第 1 分钟处。由于第 1 到第 4 分钟均不包含有趣时刻,我们按下第二个按钮(快进)。此时我们不能再按第二个按钮跳过接下来的 3 分钟,因为其中某些分钟包含有趣时刻。因此,我们从第 4 分钟观看至第 6 分钟,之后当前时间为第 7 分钟。类似地,我们再次跳过 3 分钟,然后从第 10 分钟观看至第 12 分钟。总共,我们观看了电影的 6 分钟。
在第二个样例中,电影非常有趣,因此你必须观看整部电影的 100000 分钟。
输入解题思路,AI测评打分。不知道怎么写?