Hi guys, hope you are doing well. I came across this problem 2 days ago and solved it with intuition. The same algorithm is also given in the editorial.
The problem is that I couldn't find a proper proof for that algorithm. I found this comment which seems to give some proof but I couldn't convince myself that it is a proper proof. Now, I am not able to move forward i.e. skip and solve another problems. I tried to find a proper proof for 2 days but it seems impossible. It would be great help if someone can give a proper proof. Thanks in advance.