Give back the longest parcel
transcript
One courier. Six parcels. Each parcel has hours and a deadline. Deliver the most parcels on time.
The hours are four, two, five, five, four and six. Parcel C is due at hour five. Sort the parcels by deadline first. Then go through them one at a time.
Add each parcel to a heap, and to the clock. Past the deadline? Give back the longest parcel. The longest takes the most time off.
Parcel C fits. The clock is five. Parcel E makes the clock nine, past six. Give back C, the longest. The clock is four. D goes back too. F, B and A fit.
The longest parcel takes the most time off. What is left is still on time. No other parcel gives back more time. A rule that never gives back would miss this. Sorting by deadline makes the clock test enough.
Four parcels, in sixteen hours. Giving back wins. Full breakdown in the lecture.