-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHFICRM.cpp
67 lines (65 loc) · 1.03 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test_cases;
cin >> test_cases;
while(test_cases--){
int n;
cin >> n;
int money[n];
for(int i =0; i<n; i++){
cin >> money[i];
}
int flag = 1;
int n5 = 0;
int n10 = 0;
int k = 0;
int balance;
int reg;
do{
reg = 5*n5 + 10*n10; /*returnable amount in register*/
balance = money[k]-5; /*amount to return*/
if(balance > reg){
flag = 0;
}else{
if(money[k]==5){
n5 = n5 + 1;
k++;
}else{
if(money[k]==10){
/*money = 10*/
if(n5==0){
flag = 0;
}else{
n10 = n10 + 1;
n5 = n5 - 1;
k ++;
}
}else{
/*money = 15*/
if((n5<2)&&(n10==0)){
flag = 0;
}else{
if(n10>0){
n10 = n10 - 1;
k ++;
}else{
n5 = n5 - 2;
k ++;
}
}
}
}
}
}while((k<n)&&(flag!=0));
if(flag==0){
cout << "NO" << endl;
}else{
cout << "YES" << endl;
}
}
return 0;
}