loj#P3561. 「BalticOI 2021 Day2」The short shank; Redemption
「BalticOI 2021 Day2」The short shank; Redemption
Description
Well, that certainly didn’t go as planned: While you managed to avoid the museum’s watchmen, you somehow missed that there were surveillance cameras all over the place. As a consequence, your debut as an art thief turned out to be a total disaster: You were arrested and sentenced to prison.
Because WiFi access in prison is the worst, you want to escape. From many prison dramas, you know that distractions are crucial to any escape plan. Therefore, you decided to set up a prison rebellion as a ploy.
The prison cells are aligned along a single hallway. The leftmost cell is number , the cell immediately to its right is number , and so on. Unfortunately, not all your fellow prisoners join the rebellion as planned. But you could make sure that the prisoner in cell is planning to start rebelling at time ,i.e. exactly seconds from now. Also, whenever a prisoner hears the prisoner immediately to his left rebelling, he will also start rebelling after just one second (unless he is already rebelling, of course).A prisoner who has started rebelling will never stop.
At time , the local F.R.U.IT.T.Ar.T. representative will arrive for an inspection. You figure that this will be the perfect time to escape. However, the prison wardens won’t be happy about a rebellion during an inspection. You are afraid they are going to use soundproof mattresses that can be installed between cells. If such a mattress is installed between cell and cell , the prisoner in cell will not start rebelling before time regardless of the actions of the prisoner in cell 𝑖 − 1 (or any other prisoner).
Write a program that helps you estimate your chances of success: The program shall compute the minimal number of prisoners who will rebel at time if the wardens place the mattresses optimally.
Input
The first line of input contains three integers , , and : the number of prison cells, the number of mattresses, and the time the representative arrives.
The second line contains integers , where describes the time the prisoner in cell is planning to start rebelling.
Output
The only line of output should consist of exactly one integer: the minimal number of prisoners rebelling at time .
5 1 42
13 37 47 11 42
4
5 2 5
1 9 4 6 7
2
Limits And Hints
We always have , .
- Subtask 1(15 points): .
- Subtask 2(10 points): , .
- Subtask 3(20 points): .
- Subtask 4(10 points): , .
- Subtask 5(25 pts): .
- Subtask 6(20 pts): No further constraints.