Possible Duplicate:
Algorithm to find the maximum sum in a sequence of overlapping intervals
I was solving the following modified activity scheduling (Greedy approach) problem :
Given a set S of n activities with and start time, Si and fi, finish time of an ith activity. Also given weight wi ,the cost earned by Foo for doing ith activities.
The problem is to select the activities that maximizes foo earnings. We have to return the maximum cost that can be earn by foo.Assume that Foo can only work on a single activity at a time.
Note::
This is similar to classic Activity selection problem ,here the only difference is ,for each activities ,we are given a cost wi . And the goal here is too different -Instead of finding maximum size set of mutually compatible activities ,In this problem we have to find set of those activities that maximise foo total earnings .
Example
Total activities N=4
Si fi wi
0 1 4000
2 5 100
1 4 3000
4 5 2500
Max earning=9500 (Answer)
How do i modify the classical greedy activity selection algorithm ,for solving this problem . What logic should i use to solve the above problem?