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 aipassengers exit the tram, while bi passengers 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.
- #include
- int main()
- {
- int n,m,r,a,b;
- while(~scanf("%d",&n)){
- m=0,r=0;//m记录最大人数,r记录当前车上人数
- while(n--){
- scanf("%d%d",&a,&b);
- r+=b-a;//增加人数
- if(r>m) m=r;//更新最大人数
- }
- printf("%d\n",m);
- }
- return 0;
- }