How should I solve this problem?
Problem link:- http://codeforces.com/contest/842/problem/D
I found the solution, https://www.youtube.com/watch?v=PKDQO8B0V3A
Thanks, Rachit Jain for making the video on this problem.