O(n) failed in java CHEFMGX problem in Starters 16

This is the problem Contest Page | CodeChef
I have written the solution in Java of Complexity O(n)
this is the solution : Solution: 52712503 | CodeChef
I request the viewers to point out what is the mistake in the solution that I got TLE
and the same I wrote in C and got AC :|(Solution: 52740177 | CodeChef)
why even using BufferedReader in java took so long for IO and I request some more time should be given for Java solution. `:)
or the solution should be evaluated without considering IO using predefined functions. :slight_smile:

i am having the same issue, did you found any solution for this problem.

I am using C whenever I get TLE in java.


The issue is that , while you are reading the input fast enough, your output is too slow.
You can fix that by utilizing a BufferedWriter of some kind and flush once every test case has been “printed”. Then it should AC, since your program logic is correct.

Here is the adjustment to AC: solution

Hope this helps,


1 Like

Thank you very much for helping. :slight_smile: :smiley: