Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
- int main()
- {
- fast()
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- cin>>n;
- map<int,int>mp;
- int ara[n+1];
- for(int i=0;i<n;i++)cin>>ara[i];
- bool f=true;
- for( int i=0;i<n;i++)
- {
- if(ara[i]==5)mp[5]++;
- else if(ara[i]==10)
- {
- if(mp[5]>0)
- {
- mp[5]--;
- mp[10]++;
- }
- else
- {
- f=false;
- break;
- }
- }
- else if(mp[10]>0)
- {
- mp[10]--;
- }
- else if(mp[5]>1)mp[5]-=2;
- else
- {
- f=false;
- break;
- }
- }
- if(f)cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement