CHFICRM - Editorial

There are a few things to fix in your code.
First, your first two import statements don’t have the *.
Second, you don’t need to test for whether or not T is between 0 and 100. All that the problem means is that they will not give any inputs out of those restraints.
Third, you can get rid of num15, as it isn’t used, as well as the array. You only need each input once so there’s no need to store them in an array.
Fourth is that in this part of your code:

else if(a[i]==15) {
				if(num10>0) {
					num15++;
					num10--;
				}else if(num5>1) {
					num15++;
					num5=num5-10;
				}else {System.out.println("NO");
						break;}
			}

You’re doing num5=num5-10 for some reason. I think you meant num5-=2, or num5 = num5-2.

That should help you. You’re code’s also only printing out two answers, but I think that’s a problem with my IDE.

Also, just a side note, for faster I/O, use BufferedReader br = new BufferedReader(new InputStreamReader(System.in));, and StringTokenizer st = new StringTokenizer(br.readLine()); instead of the Scanner.

Yup, got your point, that was my first code so got bit confused clear now. Thankx buddy

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

Please provide guidance . The code works as per the constraints of the question , but still gives , total score = 0% . Why ?

@anon40522502 @sebastian @ankit

@rajarshi_basu some one provide some guidance . This is second reply . How much to wait .
why do author questions when you cannot provide support ?

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

Please provide guidance . The code works as per the constraints of the question , but still gives , total score = 0% . Why ?

After each test case value of five, ten and flag should be initialized 0.

1 Like

please send me the link to your codechef submission which gives WA.

https://www.codechef.com/viewsolution/34102138
Can anyone help me …what’s wrong in this solution.

I have Written the same code in java but it is not getting accepted. Can anyone tell me what’s the problem there.

import java.util.Scanner;

public class ChefAndStrings {

public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int t = s.nextInt();

	for (int i = 0; i < t; i++) {
		int n = s.nextInt();
		int[] arr = new int[n];
		int c5=0,c10=0;

		boolean result=true;
		
		for (int j = 0; j < n; j++) {
			int coin = s.nextInt();
			if(coin==5) {
				c5+=1;
			}
			else if(coin==10) {
				if(c5>0) {
					c5--;
					c10++;
				}
				else {

					result=false;
					break;
				}
			}
			else if(coin==15) {
				if(c10>0) {
					c10--;
				}
				else if(c5>=2) {
					c5-=2;
				}
				else {

					result=false;
					break;
				}
			}
			
		}
		if(result)
			System.out.println("YES");
		else
			System.out.println("NO");
		

	}
}

}

Never break without taking whole input @shashankok @priyanka_5b4

1 Like

Oh, I see, means I have to store the complete line of input in an array.
Thanks, man.
Now my submission get accepted.:grin:

Why my code is showing NZEC error that too for line 1??? I’m new to codechef please help me out…what I’m suppose to do???why is this happening even though my code gives proper outputs???
CodeChef: Practical coding for everyone

Read the question again and see what you have to print. Also, never break without taking whole input

https://www.codechef.com/viewsolution/36183791
Still same error is showing up?? what to do???

I don’t know much about python, but there is some issue in taking input. Also, when you have found f=0 then break the loop

Your AC code CodeChef: Practical coding for everyone
There were 2 problems. First you need to see if 10 rupee coin is available then you have to give it. Second there was input of array in single line. You can not use int(input())

Okay…Thank so much you : ) I’ll implement the changes …

#include<bits/stdc++.h>

using namespace std;

#define ll long long int
#define endl “\n”

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int t;
cin>>t;

while(t--)
{
    ll n,x,c5=0,c10=0,flag=1;
    cin>>n;
    
    for(int i=0;i<n;i++)
    {
        cin>>x;
        
        if(x==5)
            c5++;
        else if(x==10 && c5>=1)
            c10++,c5--;
        else if(x==15 && (c5>=2 || c10>=1 ))
            if(c10>=1)
                c10--;
            else
                c5-=2;
    }
    
    if(flag)
        cout<<"YES"<<endl;
    else 
        cout<<"NO"<<endl;
}


return 0;

}

Can anyone tell me what wrong in this?