I tried to think of ways to solve this problem, after not being able to think of a solution which I could reason about, I read the editorial and understood the binary search solution, but I don't understand why the greedy solution works.
Could someone help reason about the greedy solution?