Getting Running Time Error. Help!

I am getting run time error for CodeChef: Practical coding for everyone.
How can I optimize this…

here is my solution(working fine for test cases)

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