Getting error of NZEC

It is working properly in Eclipse and in Codechef also, it is showing me the output when I run it for custom input, but when I click the run button, it gives this error.
Can someone please help me
Here is the code:

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

import java.util.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
static int Kill(int n, int C[], int H[])
{
int arr[] = new int[n];
for(int i=0;i<n;i++)
{
if(i-C[i]<0)
arr[0]++;

        else
            arr[i]++;    
        if(i+C[i]+1<n)
            arr[i+C[i]+1]-=1;
    }
    for(int i=1;i<n;i++)
    {
        arr[i]+=arr[i-1];
    }
    Arrays.sort(arr);
    Arrays.sort(H);
    if(Arrays.equals(arr,H))
        System.out.print("YES");
    else
        System.out.print("NO");
    return 0;
}
public static void main (String args[])
{
	// your code goes here
	Scanner S = new Scanner(System.in);
	int t = S.nextInt();
	
    while(t>0)
    {
        int n = S.nextInt();
        int C[] = new int[n];
        for(int i=0;i<n;i++)
            C[i]=S.nextInt();
        int H[] = new int[n];
        for(int i=0;i<n;i++)
            H[i] = S.nextInt();
        Kill(n,C,H);
        t--;
    }
}

}

The run button does not run it on the sample test cases, but rather empty input.

So what should I do?
It is showing this error:
Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Codechef.main(Main.java:37)

If you press the run button, you need to provide custom input.

Okay got it.
But it is showing correct output for the sample test cases but while submitting nothing is getting passed.

That means your code is wrong.

But I tried to run it with few custom inputs and the output was coming right.
This is the Zombie and the Caves question.
Can you help me that where am I going wrong?

Your solution: CodeChef: Practical coding for everyone gets the wrong answer for the following test input:

1
5
4 2 2 3 1 
4 5 4 4 4 

Edit:

It also gets the wrong for the sample testcase - the output has to match the expected output pretty much exactly, remember!

2 Likes