CF116A Tram
题目描述
线性王国有一条电车,它有n个停靠站,按照电车的运动顺序从1~n编号。
在第i站都有ai位乘客离开电车,bi位乘客上车。电车原本为空。此外,当电车到达最后一站时,所有乘客都会下车。
你的任务是计算电车的最低容量,这样电车内的人数在任何时候都不会超过这个容量。
请注意,每个停靠口都遵循先下后上的原则。
输入格式
第一行包含n(2
输出格式
打印表示电车最小可能容量的单个整数(允许为0)
翻译提供者:Karry_Huang
说明/提示
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.