Maximum remaining-long challenge april division 2



when i code in codechef online compiler then runtime error are found,
i don’t know why!!

this type of error are occur

Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(
at java.util.Scanner.nextInt(
at java.util.Scanner.nextInt(
at Codechef.main(


@sunny0712 use try & catch blocks whenever using Scanner class as i/p


You might be trying to take input when it doesn’t even exists like your program would be reading 6 numbers when there would exist only 5 in the input. Check your loops in which you are taking input and also check whether you are providing the right input data.


but if i run this code on the pc compiler then this one easily run bro without showing any error


Its coz of improper formatting of inputs by codechef like extra space or carriage return etc.

I had really bad experience due to this

Solution is not to read it int by int but rather read complete line and then split the string

String[] st = br.readLine().split(" ");

Don’t use scanner for cp. Its too slow. use bufferedReader