Why is my code giving partial correct and editorial also uses same logic https://www.codechef.com/viewsolution/34926664