Frosh Week
This problem asks us to match tasks which time slots to maximize tasks completed, with the nifty rule that only one task may be completed in each slot.
Intuitively, we want to put each task in the slot that is the next longer slot than this task. (A simple proof by contradiction shows this must be optimal). Which means we can solve this greedily.
- Sort slots and tasks by longest time
- take the longest slot
- look at the remaining tasks in longest time order for the first one that fits, and pair it.
- any longer tasks will be un-doable!
- repeat until no slots or no tasks remain
- output number of paired tasks
we have 200k, so obviously it was going to be linear-ish, and this is.