racing horses

this is my link for the code
http://www.codechef.com/viewsolution/6387322
pls help me…am getting wrong answer for this…thx in advance

You are missing the condition where after sorting, difference between some adjacent elements other than the first two can be minimum.

See this modification applied to your code and it is ACcepted here.