File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //
2+ // COMPETITIVE PROGRAMMING .cpp
3+ //
4+ // Created by Prince Kumar on 15/06/2020.
5+ // Copyright © 2020 Prince Kumar. All rights reserved.
6+ //
7+ // ---** COMPETITIVE PROGRAMMING in C++ **---
8+ // ---** PRACTICE CODING SKILLS **---
9+ // ---** CHEF AND ICECREAM **---
10+
11+
12+ #include < iostream>
13+ using namespace std ;
14+ int main (){
15+ int T; cin>>T;
16+ while (T--){
17+ int n; cin>>n;
18+ int a[3 ]= {0 ,0 ,0 }; // 5 10 15
19+ int check=0 ;
20+ for (int i=0 ;i<n;i++){
21+ int x; cin>>x;
22+
23+ if (x==5 ){
24+ a[0 ]+=1 ;
25+ }else if (x==10 ){
26+ if (a[0 ]>=1 ){
27+ a[1 ]+=1 ;
28+ a[0 ]-=1 ;
29+ }else {
30+ check++;
31+ }
32+ }else {
33+ if (a[1 ]>=1 ){
34+ a[2 ]+=1 ;
35+ a[1 ]-=1 ;
36+ }else if (a[0 ]>=2 ){
37+ a[2 ]+=1 ;
38+ a[0 ]-=2 ;
39+ }else {
40+ check++;
41+ }
42+ }
43+ }
44+ if (check==0 ){
45+ cout<<" YES" <<endl;
46+ }else {
47+ cout<<" NO" <<endl;
48+ }
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments