TLE IN MGAME

Why am i getting a TLE in the second subtask in MGAME?
my solution is CodeChef: Practical coding for everyone

Have you tried using fast i/o?
Here’s a link which might help to implement it

I was getting TLE too on using Scanner. What I did was that I used Buffered Reader for input. Buffered Reader is slightly faster than Scanner and I guess that made all the difference.

Here’s my solution with TLE in second subtask :
https://www.codechef.com/viewsolution/22297761

And here’s my solution with AC :
https://www.codechef.com/viewsolution/22297789

You can compare the two and fin that there is absolutely no change in the logic whatsoever. The only change you will notice is the Buffered Reader powered template.

Here’s my solution with TLE using Scanner and print the answer for each test case: CodeChef: Practical coding for everyone

I fixed this issue by collecting the answers in StringBuilder which takes 1.65 secs: CodeChef: Practical coding for everyone

So, the reason that you got TLE is most likely because of T, the number of test cases. (i.e, when T = 10^6). Anyway, using Buffered Reader instead of Scanner may work as well.

ok .Thanks.
It is really irritating to get a TLE when the logic is correct…:frowning: