CHEFHACK - TIME LIMIT

I have made my code in C.
I have tested using several test case and it looks fine.
But on submission it says my program has exceeded the TIME-LIMIT.

Here is the link to my code:
https://www.codechef.com/viewsolution/28522517