Need Help in Codeforces Problem

Problem link - https://codeforces.com/contest/1203/problem/D2
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