-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeasuringTraffic.java
More file actions
49 lines (46 loc) · 1.46 KB
/
MeasuringTraffic.java
File metadata and controls
49 lines (46 loc) · 1.46 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.Scanner;
public class MeasuringTraffic {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int sensors = sc.nextInt();
String[] ramps = new String[sensors];
int[] lower = new int[sensors];
int[] higher = new int[sensors];
for(int i = 0; i<sensors; i++){
ramps[i] = sc.next();
lower[i] = sc.nextInt();
higher[i] = sc.nextInt();
}
int a = -9999, b = 9999;
for(int x = sensors-1; x>=0; x--){
if(ramps[x].equals("none")){
a = Math.max(a, lower[x]);
b = Math.min(b, higher[x]);
} else if(ramps[x].equals("on")){
a = a-higher[x];
b = b-lower[x];
a = Math.max(0, a);
} else{
a = a+lower[x];
b = b+higher[x];
}
}
System.out.println(a + " " + b);
a = -9999; b = 9999;
for(int y = 0; y<sensors; y++){
if(ramps[y].equals("none")){
a = Math.max(a, lower[y]);
b = Math.min(b, higher[y]);
} else if(ramps[y].equals("on")){
a = a+lower[y];
b = b+higher[y];
} else{
a = a-higher[y];
b = b-lower[y];
a = Math.max(0, a);
}
}
System.out.println(a + " " + b);
sc.close();
}
}