Editorial for COCI '09 Contest 3 #4 Razgovori
Submitting an official solution before solving the problem yourself is a bannable offence.
First, note that a greedy strategy finds the optimal solution. Each time a detector detects calls on location , we will presume that the call is made between the leftmost and rightmost house possible. This means that all detectors between those two houses must detect at least one more call. Naive implementation of this solution can lead to time complexity and of points.
Let's try to form a better solution. We start by sorting the detectors by position. We now start from the left most detector, and maintain a stack of current calls. Of course, at the first detector, we add calls to the stack. We now process detectors one by one in order. If the number of calls detected by the current detector is greater than the number of calls on the stack, we add more calls to the stack. If it is smaller, we reduce the number of stack. We can now solve the problem by counting the number of times we remove items from the stack.
Comments