LOSTMAX- getting output in custom input but at the time of run getting NZEC

Please help me I have spend hours fixing it…still doesnot get AC

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 Main.main(Main.java:48)

My code in java of LOSTMAX of yesterday lunchtime:
https://www.codechef.com/viewsolution/14733796

Are you sure your method of input is correct? This error occurs when you ask for input and there is no input remaining.

Also, make sure you are not taking the stray newline character which is present after input of ‘T’ . That can also give you a NZEC error.

I tried taking T input without hasNextLine,I took input using just nextInt but still didnt worked for me. Can you please tell the correct way to take input in my case?

You can filter the AC JAVA submissions and yourself see how others took input. I think a that will help you better! :slight_smile:

Thank you very much. Are you able to detect what actually is wrong with my input if I take input just by nextInt?

If i recall correct, if you use nextInt, then your “String s=sc.nextLine” will catch the stray newline character and you will get a SIGSEV on accessing s[0] etc. You can see this by printing the string immediately after the input, it should most probably be a blank line.