Official

F - Fishing Editorial by en_translator


The idea of this problem was originally proposed by Keyence.

Let call the segment of length \(A\) to capture fish a net.

We can assume that the left end of the net has a fish. (Otherwise, we can shift the net to the right so that the leftmost fish in the net coincides with the left end of the end without reducing the fish.)

We brute force over \(N\) possibilities of the leftmost fish in the left when capturing the fish.

Considering the net whose leftmost end coincides with Fish \(i\), the time when each fish is contained in a net forms a segment. Thus, the fish enter and exit the net at most \(2N\) time, so we can find the optimal time to capture the fish by simulation in an \(O(N\log N)\) time.

Therefore, the problem can be solved in a total of \(O(N^2\log N)\) time.

Sample code (C++)

posted:
last update: