You have $n$ events on your calendar, defined as intervals with a start time $s_i$ and a finish time $f_i$. The events might overlap, and you want to attend all the events, so you are going to create $k$ clones of yourself to achieve this. You want to minimize the number of clones you need, $k$. A clone can attend a certain non-overlapping subset of events.
I am trying to solve the problem above. The solution in the pdf, sorts the starting times. However, I think and have proved (by showing that an optimal solution can go through a series of swaps so that it becomes the result of the wanted algorithm) that it can be done by sorting the ending times. Basically, the algorithm is:
- Sort the ending times.
- Pop the interval with the smallest ending time. If it can't be visited by any of the existing clones, then make a new clone. Otherwise, choose the clone with the largest ending time such that the interval can still be taken by that clone.
I am pretty convinced that this works, however, I am not able to find any reference on the internet about this algorithm.
Sorting by $f_i$ is optimal in another problem of finding the maximum number of events one can take but not optimal by $s_i$ so it is intuitive to extend the reasoning to this problem. Is this conceptual approach correct?