A12402 | Draw!
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You still have partial information about the score during the historic football match. You are given a set of pairs $(a_i, b_i)$ , indicating that at some point during the match the score was " $a_i$ : $b_i$ ". It is known that if the current score is « $x$ : $y$ », then after the goal it will change to " $x+1$ : $y$ " or " $x$ : $y+1$ ". What is the largest number of times a draw could appear on the scoreboard?
The pairs " $a_i$ : $b_i$ " are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.
The pairs " $a_i$ : $b_i$ " are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 10000$ ) — the number of known moments in the match.
Each of the next $n$ lines contains integers $a_i$ and $b_i$ ( $0 \le a_i, b_i \le 10^9$ ), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).
All moments are given in chronological order, that is, sequences $x_i$ and $y_j$ are non-decreasing. The last score denotes the final result of the match.
Each of the next $n$ lines contains integers $a_i$ and $b_i$ ( $0 \le a_i, b_i \le 10^9$ ), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).
All moments are given in chronological order, that is, sequences $x_i$ and $y_j$ are non-decreasing. The last score denotes the final result of the match.
输出格式
Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.
输入输出样例
输入 #1
3 2 0 3 1 3 4
输出 #1
2
输入 #2
3 0 0 0 0 0 0
输出 #2
1
输入 #3
1 5 4
输出 #3
5
In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted