(SOLVED)I am having NZEC error in my code link for my latest submission https://www.codechef.com/submit/LOSTWKND but still showing 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(1<=T && T<=1000){
int j=0,c=0;
for (j=0;j<T ;j++ ){
int A[]=new int[6];
for(int i=0;i<6;i++){
if(sc.hasNextInt())
A[i]=sc.nextInt();
}
for(int k=0;k<5;k++)
{
if(0<=A[k] && A[k]<=24)
if(1<=A[5] && A[5]<=25)
c=c+(A[5] * A[k]);
}
if(c<=120){
System.out.println(“YES”);
}
else{
System.out.println(“NO”);
}
}
}
}
}

Put your test cases as custom testcase and then run the code. You can submit without issues. I don’t know why this error isn’t fixed yet.

I tried,and it’s running with custom testcases but still after submission ,it’s showing wrong answer and subtask score 0

  1. Output may be case-sensitive (print No instead of NO and same for Yes)
  2. Doesn’t your code fail on the sample? Try printing the sum, c, after each test case and see if it’s what you expect.
1 Like

Yeah. It should be “No” or “Yes”.

A few suggestions for you.

and

Lines Such as these, where you are checking if the input is in accordance with the given constraints are completely unnecessary. If the constraints say that the number of test cases will be between 1 and 1000, it means that the number of test cases will be between 1 and 1000. You do not need to check if the value is in accordance with the given constraints.

Secondly, make sure your output is exactly as needed by the problem statement. Here you are printing “YES” and “NO” while the problem asks for “Yes” and “No”

Lastly, you can always look at other user’s submission for a problem after the contest is over and figure out where you went wrong.

2 Likes

Yeah, exactly. Shocking just how many times this casual error has propped up today :flushed: :thinking:

Also, as @itami_04 mentioned, you don’t need to check for test cases constraints in your code.
its more like just basic information, and it is of no use to check constraints in code, ig.

1 Like

i tried both of your solutions ,but it’s still showing NZEC error

Please upload the link of your latest submission which gave you the error.

2 Likes

https://www.codechef.com/submit/LOSTWKND

here’s the link for my new submission

These are the mistakes I found (ignoring compilation errors):

  1. Variable c should be inside the for loop otherwise the value of c will add for every test case.
  2. When (c <= 120), the answer should be “No” otherwise “Yes”. (You did reverse)

These are modifications:

  1. You don’t need to check constraints, they will always be valid.
  2. java.lang package is always there :slight_smile:

So the correct code will look like this:

import java.util.*;
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();
        int j=0;
        for (j=0;j<T ;j++ ){
            int c = 0;
            int A[]=new int[6];
            for(int i=0;i<6;i++){
                    A[i]=sc.nextInt();
            }
            for(int k=0;k<5;k++)
            {
               c=c+(A[5] * A[k]);
            }
            if(c<=120){
                System.out.println("No");
            }
            else{
                System.out.println("Yes");
            }
        }
    }
}

i tried that code,but it’s still showing runtime error

https://www.codechef.com/submit/LOSTWKND

This is the link to submit the solution. Please link your submission.

2 Likes

after submitting it’s showing the correct answer
thank you

thank you all for the help

:v: