-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIceCream.java
43 lines (41 loc) · 1.35 KB
/
IceCream.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
// problem: https://www.codechef.com/JUNE20B/problems/CHFICRM
// note: alwas empty input stream if breaking between taking input
import java.util.Scanner;
class IceCream{
public static void main(String[] args){
Scanner sObj = new Scanner(System.in);
int css = sObj.nextInt();
for(int zz=0; zz<css; zz++){
int n5 = 0;
int n10 = 0;
int n = sObj.nextInt();
boolean possible = true;
for(int i=0; i<n; i++){
int cash = sObj.nextInt();
if(cash == 5) n5++;
else if(cash == 10){
if(n5 == 0){
System.out.println("NO");
possible = false;
break;
}
n5--;
n10++;
}
else{
if(n10 == 0){
if(n5<2){
System.out.println("NO");
possible = false;
break;
}
n5 -= 2;
}
else n10--;
}
}
sObj.nextLine(); // I was forgetting this line
if(possible) System.out.println("YES");
}
}
}