A9697 | Watching a movie
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $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?
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 $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?
输入格式
The first line contains two space-separated integers $n$ , $x$ ( $1<=n<=50$ , $1<=x<=10^{5}$ ) — 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}<=10^{5}$ ).
It is guaranteed that for all integers $i$ from $2$ to $n$ the following condition holds: $r_{i-1}<l_{i}$ .
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}<=10^{5}$ ).
It is guaranteed that for all integers $i$ from $2$ to $n$ 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 $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.
In the second sample, the movie is very interesting, so you'll have to watch all $100000$ minutes of the movie.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted