Advertisement
jakaria_hossain

codechef- chef and icecream

Jun 11th, 2020
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  5. int main()
  6. {
  7.     fast()
  8.     int t;
  9.     cin>>t;
  10.     while(t--)
  11.     {
  12.         int n;
  13.         cin>>n;
  14.         map<int,int>mp;
  15.         int ara[n+1];
  16.         for(int i=0;i<n;i++)cin>>ara[i];
  17.         bool f=true;
  18.         for( int i=0;i<n;i++)
  19.         {
  20.            if(ara[i]==5)mp[5]++;
  21.             else if(ara[i]==10)
  22.             {
  23.                 if(mp[5]>0)
  24.                 {
  25.                     mp[5]--;
  26.                     mp[10]++;
  27.                 }
  28.                 else
  29.                 {
  30.                     f=false;
  31.                     break;
  32.                 }
  33.             }
  34.             else if(mp[10]>0)
  35.             {
  36.                 mp[10]--;
  37.             }
  38.             else if(mp[5]>1)mp[5]-=2;
  39.             else
  40.             {
  41.                 f=false;
  42.                 break;
  43.             }
  44.         }
  45.         if(f)cout<<"YES"<<endl;
  46.         else cout<<"NO"<<endl;
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement