Correct this CHFICRM solution

#include<stdio.h>
#include<stdlib.h>
int func(int n,int *ar);
int main(){
int t;
scanf("%d",&t);
while(t–){
int n,x;
scanf("%d",&n);
int ar[n];
for(int i=0;i<n;i++)
scanf("%d",&ar[i]);
x = func(n,ar);
if(x==1) printf(“NO\n”);
else printf(“YES\n”);

}
return 0;
}
int func(int n ,int *ar){
int arr[2]={0,0};
if(ar[0]>5) return 1;

for(int i=0;i<n;i++){

    if(ar[i]==5){arr[0]+=1;

          }
if(ar[i]==10){arr[1]+=1;
                arr[0]-=1;

          } if (arr[0]<0) return 1;

if(ar[i]==15){
            if(arr[1]*10>=arr[0]*5)arr[1]-=1;
                    else arr[0]-=2;

          }if (arr[0]<0 ||arr[1]<0) return 1;}

}

https://www.codechef.com/viewsolution/34443205

Your correct modified code .

1 Like

no my code gives output “yes”

here is the link to the code https://www.codechef.com/viewsolution/34430723

ok, but u can see your modified code for which it gives 100 points.
I have done one modification in your code …
https://www.codechef.com/viewsolution/34443205

Below test case create problem in your code
1
9
5 10 5 5 5 15 10 10 10
Expected o/p YES
Your code o/p NO

Problem occured due to line no. 40 of your code
if(arr[1]*10>=arr[0]*5)

1 Like

create different variables or arrays for different values of coins( 5,10,15)

thank you very much…it is clear now