Problem link — https://codedrills.io/contests/amrita-icpc-practice-session-7/problems/alibaba-and-thieves There is an editorial, but it just describes the algorithm instead of the idea (or I just don't get it). Can anyone please describe why is this correct? Also, if there are more problems where we need to sort some intervals and do something greedily, please share.