Your proposed problem can still be solved in a greedy approach. Since you've known of the original interval scheduling problem, I'll make the solution based upon what you mentioned in the question statement.
Step 1: Sort intervals based on start time.
Step 2: Maintain a "spawn" pool which uses a 2-tuple heap to maintain the data structure.
To be more precise in step 2, let's assume we have N sorted intervals I[0]
... I[N-1]
, each I
has a start
and a stop
attributes, so I[i].start <= I[i+1].start
. You have a 2-tuple heap, each tuple represents (T, M)
. T means time to leave the heap, or equivalently, the stop time of the interval; M represents the maximum current coverage if this interval is chosen. Note the order of heap is maintained by T. A variable ANS
is maintained, which keeps the current maximum coverage. Thus, the algorithm runs like this:
ANS <- 0
HEAP <- [empty]
for each sorted intervals `I[i]`:
while HEAP.empty() == false && HEAP.first_element.T < I[i].start
TMP = HEAP.first_element
HEAP.pop_first_element
if TMP.M > ANS
ANS = TMP.M
HEAP.insert((I[i].stop, ANS + I[i].stop - I[i].start))