/* 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”);
}
}
}
}
}
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.
Yeah, exactly. Shocking just how many times this casual error has propped up today
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.
These are the mistakes I found (ignoring compilation errors):
Variable c should be inside the for loop otherwise the value of c will add for every test case.
When (c <= 120), the answer should be “No” otherwise “Yes”. (You did reverse)
These are modifications:
You don’t need to check constraints, they will always be valid.
java.lang package is always there
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");
}
}
}
}