Hyobin the Liar
Time limit2sMemory limit512 MB
Given missiles landing on distinct cells in order, find the first missile after which no legal placement of k non-touching ships of length a survives.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Prefix sum
- Solved
- No attempts yet
Problem
Yeongseon and Hyobin play a battleship game often. The board is a row of cells. One player attacks and the other defends.
The defender places ships on the board. One ship covers consecutive cells. Two ships may not overlap and may not touch, so at least one empty cell sits between neighbouring ships. The attacker cannot see where the ships are.
Once the ships are placed, the attacker fires missiles. One missile strikes one cell of the board, and the attacker wins as soon as a missile hits any ship.
This time Yeongseon attacks and Hyobin defends. Hyobin hates losing, so she decides to lie. Yeongseon cannot see the ships, so Hyobin claims a missile missed even when it hit. Hyobin still admits defeat at the moment no legal arrangement is left, that is, when every way of placing the ships is hit by at least one missile fired so far.
The missiles are fired in the given order. Find which missile makes Hyobin admit defeat.
Input
The first line contains the number of cells on the board , the number of ships , and the number of cells one ship covers . ()
The second line contains the number of missiles . ()
The third line contains cell numbers, in firing order, where the missiles land. The cells of the board are numbered from to from the left, and the numbers are distinct. With no missile fired yet, placing the ships under the rules is guaranteed to be possible.
Output
Print the position in the firing order of the missile at which Hyobin admits defeat. If an arrangement that dodges every missile remains, print .