https://www.codechef.com/JUNE20B/problems/CHFICRM

#include
#include
using namespace std;
int main()
{
int test;
cin>>test;
while(test–)
{

int n,i,sum,z,j;
vector<int>a;
cin>>n;
int flag=0;
for(i=0;i<n;i++)
{
    cin>>z;
    if(z==5 || z==10 || z==15)
    a.push_back(z);
}


    for(i=0;i<n;i++)
    {
        sum=0;
        if(a[i]!=5)
        {
            a[i]=a[i]-5;
            for(j=0;j<i && sum!=a[i];j++)
            {
                sum=sum+a[j];
                if(a[j]!=0)
                a[j]=a[j]-5;

            }

            if(sum!=(a[i]))
                flag=1;
                //a[i]=a[i]-5;
        }
    }
    if(flag==1)
    cout<<"NO"<<endl;
else
    cout<<"YES"<<endl;

}
}
what is the problem with my code ?

See this:

#include <bits/stdc++.h>
using namespace std;
int main(){
   int t;
   cin>>t;
   while(t--){
      int n;
      cin>>n;
      int x = 0, y = 0,q;//x for notes of 5 and y for notes of 10 
      //notes of 15 can't be used for any exchange, so just leave them
      bool flag=true; //whether he could sell or not

      for(int i=0;i<n;i++){
         cin>>q;
         if(q==15){
            //for note of 15, choose 1 of y exchange over 2 of x
            if(y>0){
               y--;
            } 
            //we don't have a y note now, we have to use 2 x notes
            else if(x>1){
               x-=2;
            }
            //if not possible, leave
            else{
               flag=false;
            }
         } else if(q==10){
            //return 1 x note
            if(x>0){
               x--;
            } 
           //if not possible, leave
            else{
               flag=false;
            }
            y++;//extra 10 note
         } else {//now the note would be of 5
            //so we get an extra x note
            x++;
         }
         if(!flag)break;
      }
      if(flag){
         cout<<"YES\n";
      } else {
         cout<<"NO\n";
      }
   }
   return 0;
}

If you didn’t understand anything please ask.