Unable to come up with a formal proof of optimality for algorithm A for the given problem. Have convinced myself that it is possible to execute some optimal schedule O in increasing order of the events' deadline. But don't know how to formally prove that extract_max operation converges to an optimal solution.
Problem
: Given a list of events with deadline date 'd' and duration 'l' days, provide algorithm to select events such that maximum number of them can be chosen. Of course, each event must be scheduled such that it finishes by deadline date 'd', it must run continuously for its duration 'l' days, and only one event can run at any given time.
**Greedy Algorithm A:**
Create max_heap S //schedule
Sort events by their deadline (increasing).
for(j=0;j<events.size();j++)
{
If you can incorporate event j into schedule S, do so.
Else, if(longest event in S > length of j) swap it with j.
}
Return S;
END