Need Help in Codeforces Problem

Problem link - Problem - D2 - Codeforces
Am not able to understand the editorial of this problem.
Can someone please help me to solve this problem.

Watch the screencast with commentary by Um_nik.

2 Likes