Editorial for WC '17 Contest 3 S2 - GleamingProudChickenFunRun
Submitting an official solution before solving the problem yourself is a bannable offence.
This problem can be solved with a greedy approach, by generally considering the clips from earliest to latest (though note that this is not a well-defined ordering itself, as clips have two potential endpoints to sort by).
Let clip be the clip which ends the earliest (the one with the smallest value). Assuming that we'd like to exclude clip from in an effort to minimize , we'll need to include in some clip which overlaps with clip (such that ). If there are multiple valid clips like this, we should choose the one which ends the latest (the one with the largest value), so that it's more likely to take care of overlapping with more later-occurring clips. Note that the chosen clip may end up being equal to clip . Having included clip in , we can effectively ignore all other clips overlapping with it (clips such that ). This leaves us with just the set of clips such that , on which the above process can be repeated – that is, we'll next look for the clip which ends the earliest of the remaining ones. Once there are no remaining clips, we can stop, as all clips will have been accounted for (by either having been included in , or by being known to overlap with a clip in ).
If we sort the clips in non-decreasing order of (in time), the above greedy process can be implemented naturally in time. We can maintain an index of the next clip which we'll try to omit from , scan through all clips each time to find the optimal clip to include in , and then move forwards to the next earliest clip which doesn't overlap with clip .
Improving the time complexity to is required to earn full marks, and there are several different approaches which accomplish this. One possibility is to create a reduced list of clips in which all clips which are contained entirely within other clips have been omitted. This new list has two useful properties: both the values and the values of its clips are sorted, and any optimal clip which we might want to include in must still be part of it. We can then maintain an index into this new list, and move it forwards as necessary when searching for each clip to include in , without needing to scan through the entire list each time.
Comments