-
Notifications
You must be signed in to change notification settings - Fork 0
/
Train.java
55 lines (43 loc) · 1.45 KB
/
Train.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
53
54
55
import java.util.Scanner;
public class Train {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int capacity = sc.nextInt();
int n = sc.nextInt();
int currentCapacity = 0;
int peopleWaiting = 0;
boolean possible = true;
for(int i =0; i < n; i++)
{
currentCapacity -= sc.nextInt();
if(currentCapacity > capacity || currentCapacity < 0)
{
possible = false;
}
currentCapacity += sc.nextInt();
if(currentCapacity > capacity || currentCapacity < 0)
{
possible = false;
}
peopleWaiting = sc.nextInt();
if(currentCapacity < capacity && peopleWaiting > 0)
{
possible = false;
}
}
if(currentCapacity != 0)
{
possible = false;
}
if(peopleWaiting != 0)
{
possible = false;
}
if(possible)
{
System.out.println("possible");
}else{
System.out.println("impossible");
}
}
}