Need Help in CHKPTS

Here is the link to problem https://www.codechef.com/problems/CHKPTS . I am trying the implement the idea from the editorial but it’s giving WA. can someone help here . Here is the link to my code https://www.codechef.com/viewsolution/34633642 and this is editorial link : CHKPTS - Editorial