WA in CHN16F

problem link:
https://www.codechef.com/problems/CHN16F
solution link:
https://www.codechef.com/viewsolution/16581767

can somebody help me out with the error in my solution…thanks in advance:)

just increase the size of array a,i made it of size 10^6 and it passed
your solution:https://www.codechef.com/viewsolution/16598393