CF1131B.Draw!
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi) , indicating that at some point during the match the score was " ai : bi ". 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 " ai : bi " 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≤n≤10000 ) — the number of known moments in the match.
Each of the next n lines contains integers ai and bi ( 0≤ai,bi≤109 ), 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 xi and yj 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.