Help with CHEFEXQ

I have done the code according to the editorial but getting some WA but no TLE. It would be nice to get some help…

Code Link - Solution: 17183054 | CodeChef

Problem Link - Contest Page | CodeChef

Thank you

//