Why never giving back fails
transcript
Take a parcel if it fits. Never give a parcel back. Does that find the best plan?
The hours are five, six and four. The deadlines are ten, six and nine. Sorted by deadline, the six-hour parcel is first.
Take it. The clock is six. Six plus four is ten. Too late for nine. Six plus five is eleven. Too late for ten. Only one parcel is kept. The early six-hour parcel blocked both of the others.
Four and five hours fit together. They finish at hour nine. Two parcels, not one. A rule that gives the six hours back would find this. Giving back is what the heap is for.
Sort by deadline first. Add each parcel to a max-heap. Past a deadline? Give back the longest. Now two parcels fit, not one. The heap finds the longest in log steps.
The early parcel blocked two others. Give it back. Full breakdown in the lecture.