-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrainPassengers.java
More file actions
32 lines (32 loc) · 891 Bytes
/
Copy pathTrainPassengers.java
File metadata and controls
32 lines (32 loc) · 891 Bytes
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
//Name: Nguyen Minh Hieu
//https://open.kattis.com/problems/trainpassengers
import java.util.*;
public class TrainPassengers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int capacity = sc.nextInt();
int no_stations = sc.nextInt();
sc.nextLine();
//int last = 0;
int on_train = 0;
for (int i = 0; i < no_stations; i++) {
int left = sc.nextInt();
int enter = sc.nextInt();
int stay = sc.nextInt();
sc.nextLine();
on_train += enter;
on_train -= left;
if (i == no_stations-1 && (stay != 0 || enter !=0 || on_train != 0)) {
System.out.println("impossible");
return;
} else if (on_train > capacity || on_train < 0) {
System.out.println("impossible");
return;
} else if (on_train < capacity && stay > 0) {
System.out.println("impossible");
return;
}
}
System.out.println("possible");
}
}