The exact problem is here

https://codeforces.com/contest/1019/problem/D

and also tried to understand the problem given in this editorial

https://codeforces.com/blog/entry/61161

but not able to understand. Can anyone help me to understand the solution of this problem.