Chef and time Machine

Problem :- https://www.codechef.com/problems/CHEFTMA

I am getting the wrong answer. Can anyone explain to me the reason and provide a test case where my solution is wrong.

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