December Lunch Time Optimal Sorting

https://www.codechef.com/viewsolution/55441654

My code is working for my test cases. But I dont know where it is failing . Can anyone please help

7
4 1 5 2 6 3 7

Correct Ans- 5
Your Ans- 6

Thanks a lot bro