Unable to find bug in codechef problem SETELE

Link to the problem SETELE
I coded exactly like mentioned in the editorial, but unable to get AC. Do you see any obvious bug that I can’t see in my solution below. Thanks in advance!

Code:
https://www.codechef.com/viewsolution/24407544