https://mirror.codeforces.com/contest/2154/submission/345771218, this is my solution of the problem. I am not sure why it's failing I am using the exact same idea as in editorial. It's giving TLE due to some implementation error. Can you someone please correct. Any input is welcome. I have tried to comment the code a bit to make the parts of it understandable. Please ask for any clarification if needed. Thanks



