NZEC error in the code

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
{
Scanner sc=new Scanner(System.in);
int n,q,t,i,j,maxi=-1;
t=sc.nextInt(); //error refers here
for(i=1;i<=t;i++)
{
n=sc.nextInt();
q=sc.nextInt();
int[] narr=new int[100000];
int[] qarr=new int[100000];
int[] ans=new int[100000];
for(j=0;j<n;j++)
{
narr[j]=sc.nextInt();
ans[j]=Math.max(narr[j],maxi);
if(narr[j]>maxi)
maxi=narr[j];
}
for(j=0;j<q;j++)
{
qarr[j]=sc.nextInt();
System.out.println(ans[qarr[j]-1]);
}
maxi=-1;
}
}
}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Also - what Problem are you trying to solve? :slight_smile:

Edit:

I don’t see any recent Submissions from you: are you trying to Run without providing Custom Input?

i had solved the same problem in C++ and it got solved but in Java it shows runtime error.
Problem Code : MAY19F1
in JAVA(hotspot 8u112)

Edit : Amazing, while running it is showing runtime error and when I submitted it showed successful answer.
https://www.codechef.com/viewsolution/28021946

I scratched my head a lot…I ran without providing custom input as I thought there might be sample cases…Switched from HackerRank…Thanks :slight_smile:

1 Like