What's the error in my approach (ACM14AM5)

problem- https://www.codechef.com/problems/ACM14AM5
code- https://www.codechef.com/viewsolution/27534482