Frosh Week

From programming_contest
Revision as of 16:07, 10 December 2017 by imported>Kmk21 (Created page with "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 t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

  1. Sort slots and tasks by longest time
  2. take the longest slot
  3. 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!
  4. repeat until no slots or no tasks remain
  5. output number of paired tasks

we have 200k, so obviously it was going to be linear-ish, and this is.