Take it, then give back the longest
transcript
A student picks short courses. Each has a number of days and a last day. Take them, then give one back.
Sort the courses by last day. Add each course to the total. If the total passes the last day, give back the longest.
The five-day course fits its deadline. The four-day course makes the total nine. That is past day six. Give back the five-day course. The total is four. The two-day course fits. Two courses are kept.
Giving back keeps the same count of courses. One leaves, and one stays. It also makes the total as small as it can be. So every later course has the most room.
Never giving back keeps one course. Giving back keeps two. Together they use six days.
Sort by the deadline, not by the length. The deadline closes the decision. Give back the longest, not the newest.
Sort by the deadline. Give back the longest course. Full breakdown in the lecture.