-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainpassengers.java
52 lines (42 loc) · 1.2 KB
/
trainpassengers.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package progContest;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.ArrayList;
public class trainpassengers {
public static void main(String[] args) throws FileNotFoundException {
//File in = new File("C:\\Users\\clafa\\eclipse-workspace2\\ProgContest\\src\\progContest\\trainpassengersinput.txt");
//Scanner read = new Scanner(in);
Scanner read = new Scanner(System.in);
int capacity = read.nextInt();
int rows = read.nextInt();
read.nextLine();
int currPassengers = 0;
int waiting = 0;
boolean isImpossible = false;
while(read.hasNext()) {
int leaving = read.nextInt();
int entering = read.nextInt();
waiting = read.nextInt();
read.nextLine();
if(leaving > currPassengers) {
isImpossible = true;
break;
}
currPassengers = currPassengers + entering - leaving;
if(currPassengers > capacity || currPassengers < 0 || (waiting > 0 && currPassengers < capacity)) {
isImpossible = true;
break;
}
}
if(currPassengers > 0 || waiting > 0) {
isImpossible = true;
}
if(isImpossible) {
System.out.println("impossible");
}
else {
System.out.println("possible");
}
}
}