Editorial for COCI '20 Contest 5 #4 Planine
Submitting an official solution before solving the problem yourself is a bannable offence.
Notice that for each valley, there is a segment of -coordinates for which a fairy illuminates this valley.
In the first subtask, the segments are determined by the points adjacent to the valley. We can just intersect the lines with the line . The complexity of this step is .
After we find the segments, we have the well-known problem of covering a set of segments with the minimum number of points. The greedy algorithm where we sort the segments by their right end is correct, and the complexity is .
When the mountain tops have different heights, there is an issue: it can happen that a nonadjacent mountain top "blocks the view":
For the second subtask, we can look at each valley-mountain top line, and determine the segment from the intersections of the lines with the line . The complexity is .
For the full solution, note that the mountain top which "blocks the view" is actually the penultimate point on the upper convex hull of all the points up to the current valley:
Hence, maintaining the convex hull is enough to find the left ends of all the segments. We can do the same thing (but backwards) for the right ends. The complexity of this part is .
Comments