CHFICRM - Editorial

You have to print in capital letter

l[j] what type of index specifictionit is

n=int(input())
for i in range(n):
a=int(input())
l=list(map(int,input().split()))
i=0
if(l[0]==5): #first line should be alwayd be 5
while(len(l)!=1): # comes out when the list has only one element
if l[i+1]//5==1: # No need to give change
c=l[i]+l[i+1]
l.pop(i+1)
l.pop(i)
l.insert(i,c)
else: #must give change
k=l[i+1]//5-1
if(k5<=l[i]):
c=l[i]+l[i+1]-k
5
l.pop(i+1)
l.pop(i)
l.insert(i,c)
else: # this for 5 15
print(“NO”)
exit()

    if(l[0]>=0):
        print("YES")
    else:
        print("NO")
            
else:
    print("NO")

Could you please check and tell me where did i gone wrong

send the submission link
@jagadeesh1729

https://www.codechef.com/viewsolution/34676808
thank you sir. I am glad if I Know did i gone wrong. Eargly waiting for your reply

your code gives WA for many cases like :
2
3
5 10 10
5
5 5 10 15 15
It should give NO two both cases

Keep the count of coins of 5 and 10 it would be easier to solve. Your code stores amount of money you have that’s why it is giving WA.
Also, use try expect pass to avoid certain errors.

My code was paritally accepted, which condition have I missed or went wrong.

#include
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n,i,j,k=0,count=0,s,five=0,z;
cin>>n;
int a[n],chef[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{ five =0;
if(a[i] == 5)
{
chef[k] = 5;
k++;
count++;
}
else if(a[i] == 10)
{
for(j=0;j<k;j++)
{
if(chef[j] == 5)
{
chef[j] = 0;
chef[k]=10;
k++;
count++;
break;
}
else
continue;

         }
        }
   else if(a[i] == 15)
    { 
      for(z=0;z<k;z++)
      {
        if(chef[z] == 10)
        { 
        chef[z] =0;
        chef[k] = 15;
        k++;
        count++;
        five =0;
        break;
        }
        
     else 
       {
       if(chef[z] == 5 && k>1)
        {  
          five++;
         
          if(five == 2)
          {
            chef[z] = 0;
            chef[k] = 15;
            k++;
            count++;
            chef[s] = 0;
            five =0;
            break;
          }
          else
           s=z;
        }
        }
       }
       
      }
    }
    
if(count == n)
cout<<"YES"<<endl;
  else
  cout<<"NO"<<endl;
}

}

#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–){

int n,cnt5=0,cnt10=0,i;
string res="YES";
cin>>n;
while(n--){
cin>>i;
if(i==5)
cnt5++;
 if(i==10){
cnt10++;
cnt5--;
 }
if(i==15)
{ 
if(cnt10>0)
cnt10--;
else 
cnt5-=2;
 }
    if(cnt5<0 || cnt10<0)
    res="N0";
 }
    cout << res <<endl;
}
return 0;

}
why is this code wrong? I’m not able to find the error.

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);

	int T=sc.nextInt();
	if(T>0 && T<100){
	while(T-->0){
		
		int N= sc.nextInt();
		
		int a[]= new int[N];
		
		int num5=0, num10=0 ,num15=0, i=0;
		
		for(i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		
		for(i=0;i<N;i++) {
			
			if(a[i]==5) {
				num5++;
			}else if(a[i]==10){
				if(num5>0) {
					num10++;
					num5--;
				}else {System.out.println("NO");
						break;}
				
			}else if(a[i]==15) {
				if(num10>0) {
					num15++;
					num10--;
				}else if(num5>1) {
					num15++;
					num5=num5-10;
				}else {System.out.println("NO");
						break;}
			}
		}
		
		if(i==N) {
			System.out.println("YES");
		}
		
	}
}

}

}

My code is running in eclipse but not in here, what mistake am i doing here?

I am getting subtask 2 wrong. Can anyone help ?
https://www.codechef.com/viewsolution/34747587

When price is 15, condition should be coinOfFive>=2

Thank You…

I tried this: -
But with custom input It’s working fine but not passing all the test cases at the time of Submission.
Can you please tell me where am I lagging behind??

#include <iostream>
using namespace std;
typedef long long ll;
int main() {
ll t;
cin>>t;
while(t>0)
{   int f = 0;
ll n;
cin>>n;
ll arr[n];
for(ll i=0;i<n;i++)
{
    cin>>arr[i];
}
if(arr[0]!=5)
{   
    cout<<"NO"<<"\n";
    
}
else
{  ll c=arr[0];
   for(ll i=1;i<n;i++)
{
    if(arr[i]==5)
       { c = c + arr[i];
         f = 1;

       }
    else if((arr[i] - c) == 5)
       {
         c = arr[i] - c;
         f = 1;
         
        }
    else
       {   
           f = 0;  
           break;
       }
}
}
if(f==1)
   cout<<"YES"<<"\n";
else if(f==0 && arr[0]==5)
  cout<<"NO"<<"\n";
t--;
}
return 0;
}

see test case :
5 10 10
it is giving YES whereas answer should be NO.

Keep the count of number of coins of 5 and 10.

I believe that Answer should be YES, because he first got 5 coins and when someone buys an icecream, which costs 5 coins, so he will give him 5 back and will be left with 5 coins. And same procedure for the next icecream.

I might be wrong in understanding the question.
But I think this pattern should yield YES.

If I am wrong in understanding this question. Can you please elaborate this question in an easier way?
Because I gave the solution in the manner I understood this question.

First he got 5 rupee coin. On second purchase when customer gave him a 10 rupee coin he returned the 5 rupee coin and thus left with a 10 rupee coin. For third purchase customer again gave him a 10 rupee this time he has not left with a 5 rupee coin so this transaction is not possible.

So keep the count of coins of 5 and 10.
And handle the case of 15 rupee coin carefully.

Ok… I thought that 5 10 and 15 are in denominations. I didn’t think them as whole coin.
Ok Thank you for clarifying this.
Now I have design another solution.
Thank you so much.