forked from Anishukla/Codechef_Hacktoberfest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHFICRM.cpp
56 lines (53 loc) · 849 Bytes
/
CHFICRM.cpp
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
56
//Link to solution https://www.codechef.com/viewsolution/33660350
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,j;
cin>>t;
for(j=0;j<t;j++){
int i,n;
cin>>n;
int arr[n];
for(i=0;i<n;i++){
cin>>arr[i];
}
int c5=0,c10=0,c15=0;
int flag=0;
for(i=0;i<n;i++){
if(arr[i]==5){
c5++;
}
else if(arr[i]==10){
if(c5==0){
flag=1;
break;
}
else{
c5--;
c10++;
}
}
else if(arr[i]==15){
if(c10>0){
c10--;
c15++;
}
else if(c5>1){
c5 = c5-2;
c15++;
}
else{
flag=1;
break;
}
}
}
if(flag==1){
cout<<"NO\n";
}
else{
cout<<"YES\n";
}
}
return 0;
}