Wrong answer for Racing horses problem

I am getting WA …but as I think the code is correct. Can you please tell me what’s the problem with the code:

Question link:

My solution link:
http://www.codechef.com/viewsolution/6397926

There is one silly mistake in the last for loop.

Check that once. Debugging it yourself will help you in future. :slight_smile:

Try your best to find the mistake and feel free to leave a comment if you are not able to find it out.
Thanks.

I am also facing the same problem but I have implemented my solution in different way than the above one.
Please review it.
My code: https://www.codechef.com/viewsolution/21618777