火车
Problem Description
你的任务是计算火车的最小容量确保任何时候火车上的总人数都不会超过这个容量。注意,在每个车站,上车的乘客都是在下车乘客都下来之后才开始上的。
Input
每组输入数据第一行只有一个整数n (2 <= n <= 1000) ——车站的总数。
接下来是n行,每行有两个整数Ai和Bi(0 <= Ai,Bi <= 1000)——分别代表在第i个车站下车和上车的乘客数。车站是沿照火车前进方向从起点到终点按顺序给出的。
注意起点站不会有人下车,终点站不会有人上车。
Output
Example Input
1 4 0 3 2 5 4 2 4 0
Example Output
6
import java.util.*; |
02 |
import java.io.*; |
03 |
import java.text.*; |
04 |
public class Main
{ |
05 |
public static void main(String
args[]){ |
06 |
Scanner
input = new Scanner(System.in); |
07 |
int t
= input.nextInt(); |
08 |
while (t> 0 ){ |
09 |
t--; |
10 |
int n
= input.nextInt(); |
11 |
int ai,bi,abi; |
12 |
int sum
= 0 ; |
13 |
int []
sum1 = new int [ 1010 ]; |
14 |
|
15 |
for ( int i= 0 ;i<n;i++){ |
16 |
ai
= input.nextInt(); |
17 |
bi
= input.nextInt(); |
18 |
abi
= bi - ai; |
19 |
if (i== 0 ){ |
20 |
sum1[ 0 ]
= abi; |
21 |
} |
22 |
else { |
23 |
sum1[i]=sum1[i- 1 ]+abi; |
24 |
} |
25 |
|
26 |
} |
27 |
Arrays.sort(sum1); |
28 |
System.out.println(sum1[sum1.length- 1 ]); |
29 |
System.out.println(); |
30 |
} |
31 |
|
32 |
} |
33 |
} |