Skip to main content

Checkpoint: The Latest Finish

Challenge on lesson: Checkpoint — Prove, Then Sort

CHALLENGE
Difficulty: advanced+25 XP

**Task.** n jobs; job i takes t_i and has deadline d_i. All jobs run one after another in the order you choose; a job finishing at time F has lateness F − d_i. Choose the order minimizing the maximum lateness. Print that minimum. **Constraints:** 1 ≤ n ≤ 200000; 1 ≤ t_i ≤ 1000; 1 ≤ d_i ≤ 10^5. Times reach ~2·10^8 — use 64-bit. **Budget check:** n! orders are unthinkable; O(n log n) for one sort plus one sweep is the whole budget.

Back to lesson: Checkpoint — Prove, Then Sort