Help with MTRICK

I have tried to optimize my code in almost every possible way yet i’m getting TLE. The link to problem is http://www.codechef.com/JAN14/problems/MTRICK and to my solution is http://www.codechef.com/viewsolution/3225847 . Kindly provide any suggestions. Thanks in advance.

You shouldn’t ask for help during an active contest … besides no one will be able to see your solution except you.

1 Like

I think I can add this general answer, that I got from setter:

“Well, it’s not guaranteed that problem can be solved using any language like Python or Java, however solutions on C, C++ and Pascal exist so you have to optimize your program. If you are sure that your algorithm is the fastest possible then try to optimize your I/O methods. There is no limit on number of submissions and penalties for wrong ones, so try your best to get AC.”

I asked if there is worst case in tests, I didn’t get further info.