Problem description

Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bipassengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.

Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

Input

The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.

Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.

  • The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.
  • At the last stop, all the passengers exit the tram and it becomes empty. More formally, .
  • No passenger will enter the train at the last stop. That is, bn = 0.

Output

Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

Examples

Input

4
0 3
2 5
4 2
4 0

Output

6

Note

For the first example, a capacity of 6 is sufficient:

  • At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
  • At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.
  • At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.
  • Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.

Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.

解题思路:题目的意思就是找出上下车过程中车内的最多人数,即为车的至少容量,简单水过。题目已经保证了一开始下车的人数为0,最后上车的人数也为0,并且最后车内的人将全部下车。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,nowcap=,maxcap=;
cin>>n;
while(n--){
cin>>a>>b;
nowcap-=a;nowcap+=b;
maxcap=max(maxcap,nowcap);
}
cout<<maxcap<<endl;
return ;
}

C - Tram的更多相关文章

  1. [最短路径SPFA] POJ 1847 Tram

    Tram Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14630 Accepted: 5397 Description Tra ...

  2. POJ 1847 Tram (最短路)

    Tram 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/N Description Tram network in Zagreb ...

  3. poj 1847 Tram【spfa最短路】

    Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12005   Accepted: 4365 Description ...

  4. (简单) POJ 1847 Tram,Dijkstra。

    Description Tram network in Zagreb consists of a number of intersections and rails connecting some o ...

  5. Codeforces Round #386 (Div. 2) C. Tram

    C. Tram time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  6. Tram

    Tram 题目大意:给你一个图,这个图上有n点和边.点上有开关,开关开始指向一条道路,拨动开关可以使开关指向由开关出发的任意一条路径,读入,a,b,求,至少要拨动几次才能从a点走到b点. 注释:n&l ...

  7. POJ1847 Tram

    Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20274   Accepted: 7553 Description ...

  8. poj1847 Tram(最短路dijkstra)

    描述: Tram network in Zagreb consists of a number of intersections and rails connecting some of them. ...

  9. POJ 1847 Tram (最短路径)

    POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...

  10. POJ1847:Tram(最短路)

    Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20116   Accepted: 7491 题目链接:http:/ ...

随机推荐

  1. CAD绘制一个箭头(com接口)

    1 2 3 4 5 6 7 8 //绘制一个箭头  axMxDrawX1.PathMoveToEx(1000, 300, 10, 10, 0);  //设置路径下一点  axMxDrawX1.Path ...

  2. java 异常报错总结

    1.java.lang.ArithmeticException:这是算数异常 比如分母位0 2. java.lang.ArrayIndexOutOfBoundsException:数组下标越界异常 3 ...

  3. H5及微信中唤起app的解决方案

    今天我们就来说说这个callapp-lib 我的接到的需求大概是这样的 如果检测到不是在app里面用webview打开的页面就会显示上面的立即打开按钮, 点击的话会判断是否在微信中, 如果在微信中打开 ...

  4. jdk编译安装及tomcat编译安装

    这里我安装的jdk版本为1.8版本,tomcat版本为8.5(请上官网下载) 运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) jdk部署: 1.前往软件所在路径 [root@web ...

  5. TCP/IP UDP 协议首部及数据进入协议栈封装的过程

    数据的封装 UDP 封装 TCP 封装 IP 封装 检验和算法 当应用程序用TCP传送数据时,数据被传送入协议栈中,然后逐一通过每一层直到被当作一串比特流送入网络 注: UDP数据TCP数据基本一致. ...

  6. Problem 29

    Problem 29 Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: 仔细看看以下a与b的组合 22=4, 2 ...

  7. PAT 1109 Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  8. mac上的svn命令

    Mac 终端添加代码到SVN从SVN拉取代码步骤:1.cd /Users/指定路径(本地路径)2.svn checkout https://xxx.xxx.xx/svn/project(服务器路径) ...

  9. 【codeforces 767C】Garland

    [题目链接]:http://codeforces.com/contest/767/problem/C [题意] 一棵树; 树上的每个节点都有一个权值; 让你把一棵树切掉两条边; 然后把这棵树分成了3个 ...

  10. python实现字符串之间的映射

    类似于凯撒密码一样的加密 # *-* coding=utf-8 *-* import string intab = string.lowercase outtab = 'qwertyuiopasdfg ...