Help Needed In Codeforces Problem C

Hello everyone, Could u please help me in solving this problem?

Problem - C - Codeforces

I have tried solving it myself and seen the editorials but I didn’t understand their approach
Link to the editorials :-https://codeforces.com/blog/entry/10842