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. 使用原生JS的AJAX读取json全过程

    首先ajax(async javascript and xml)是用于前端与后端文件比如xml或者json之间的交互.他是一种异步加载技术,意味着你点击某个加载事件是再也不用刷新整个页面,而是发送局部 ...

  2. Web 常用

    System.Web.Hosting.HostingEnvironment.MapPath(); HttpUtility.UrlEncode();

  3. idea热更新配置

    idea部署热启动如下,经过本人实验 在这里只能选择exploded因为它支持热部署 在这里选择如下 到这里已经完成热部署了,如果有问题欢迎反馈给我,我会及时回复

  4. [luogu3155 CQOI2009] 叶子的染色(树形dp)

    传送门 Solution 十分简单的树形dpQwQ,转移关系:父亲染了儿子不用染 只需要确定根就是简单树形dp,而其实根可以随便取一个非叶子节点 可以分情况讨论发现答案并不会改变 Code //By ...

  5. golang实现高阶函数之map

    package main import "fmt" func iMap(num []int, f func(a int) int) []int{ var r []int for _ ...

  6. VsCode 格式化插件配置

    Beautify 1.在工作目录下建立.jsbeautifyrc文件: { "brace_style": "none,preserve-inline", &qu ...

  7. 24.通过ngram分词机制实现index-time搜索推荐

    一.ngram和index-time搜索推荐原理     1.什么是ngram     假设有一个单词:quick,在5种长度下的ngram情况如下: ngram length=1,q u i c k ...

  8. Silverlight之我见——DataGrid数据验证

    <UserControl x:Class="DataValidationSample.MainPage" xmlns="http://schemas.microso ...

  9. GeoTrust 企业(OV)型 SSL证书

      GeoTrust True BusinessID SSL证书属于企业验证(OV)级别的SSL证书,验证域名所有权,验证企业单位信息,提供40位/56位/128位,最高支持256位自适应加密,被20 ...

  10. 【codeforces 510C】Fox And Names

    [题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...