Can't find solution to this

Here is a question: Problem - D - Codeforces

I tried to understand, but could understand editorial properly.
I searched on YouTube people have skipped this question.
If you can provide the “explanation” then it will be great.