-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathCodeforces_0349A_Cinema_Line.java
More file actions
44 lines (42 loc) · 1.21 KB
/
Codeforces_0349A_Cinema_Line.java
File metadata and controls
44 lines (42 loc) · 1.21 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
// AC: 560 ms
// Memory: 0 KB
// .
// T:O(n), S:O(1)
//
import java.util.Scanner;
public class Codeforces_0349A_Cinema_Line {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), count100 = 0, count50 = 0, count25 = 0;
boolean flag = true;
for (int i = 0; i < n; i++) {
int coin = sc.nextInt();
if (coin == 25) {
count25++;
} else if (coin == 50) {
if (count25 <= 0) {
flag = false;
break;
} else {
count25--;
count50++;
}
} else {
// two change coin ways.
if (count25 < 3 && (count25 <= 0 || count50 <= 0)) {
flag = false;
break;
} else {
if (count50 >= 1) {
count25--;
count50--;
} else {
count25 -= 3;
}
count100++;
}
}
}
System.out.println(flag ? "YES" : "NO");
}
}