-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTram.java
33 lines (28 loc) · 800 Bytes
/
Tram.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class Tram{
public static int countPassanger(int[] z,int[] y){
int total=0;
int x=0;
for (int i=1;i< z.length;i++){
total=(z[i]+x)-y[i];
if(total<0){
x=0;
}else x = total;
}
return total;
}
public static void main(String[] args) {
Scanner ens = new Scanner(System.in);
int n = ens.nextInt();
ens.nextLine();
int[] a = new int[n];
int[] b = new int[n];
for (int i=0;i<n;i++){
String[] s = ens.nextLine().split(" ");
a[i]=Integer.parseInt(s[0]);
b[i]=Integer.parseInt(s[1]);
}
int maxCapacity = countPassanger(a,b);
System.out.println(maxCapacity);
}
}