Rikka with RCPC
Time limit1sMemory limit512 MB
Pick the days to answer questions so the total attack is minimized, where a free answer needs K consecutive ignored days before it.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Prefix sum, Sliding window
- Solved
- No attempts yet
Statement
Rikka is going to hold a worldwide competition, RCPC (Rikka's collegiate programming contest).
Preparing for the contest takes Rikka days. Meanwhile, the official QQ group of RCPC receives many questions from contestants, coaches, and even melon eating people. Rikka decides to ignore the QQ group on some of the days.
However, always ignoring questions may make contestants angry. Before the start of Day , the angry value of contestants is . At the beginning of the -th day, the angry value increases by . Then:
- If is strictly larger than a threshold , contestants will be extremely angry, and Rikka receives points of attack. At the end of this day, is cleared to .
- If is no larger than and Rikka chooses to ignore questions, nothing happens on this day.
- If is no larger than and Rikka decides to answer questions, and Rikka ignored all questions on the previous days, i.e. from Day to Day , contestants will feel the hardness of Rikka. Rikka receives no attack, and at the end of this day, is cleared to .
- Otherwise, even though Rikka chooses to answer questions, contestants still blame Rikka for answering so slowly, and Rikka receives points of attack. At the end of this day, is cleared to .
Your task is to decide which days to answer questions so that the total attack Rikka receives is minimized.
Input
The first line contains three integers , , and (, ).
The second line contains integers ().
Output
Output a single integer, the answer.
Hint
For the first sample, one optimal plan is to answer questions on Day and Day :
- On Day , the angry value is , so Rikka receives points of attack.
- On Day , the angry value is , so nothing happens.
- On Day , the angry value is . Since Rikka did not answer on Day , contestants feel the hardness of Rikka, so nothing happens.
- On Day , the angry value is , so nothing happens.