#P1929. 迷之阶梯
迷之阶梯
Description
To enter the ruin, one must pass a mysterious staircase. You must climb it in the required manner; otherwise, you cannot ascend. The rules are as follows:
-
If the next step’s height exceeds the current step’s height by exactly , you may step onto it directly.
-
Except for the first step, you may retreat from the current step to the previous step.
-
After you have retreated consecutively times, you may make one jump to any step whose height is at most the current step’s height . For example, suppose you are now at step , having retreated from step . Then you may jump to any step whose height is no more than the current step’s height . This jump counts as a single move.
You start at step . Due to time pressure, you need to reach the top step using the fewest moves. Please compute the minimum number of moves.
Input Format
- The first line contains an integer , the number of steps.
- The second line contains integers, the heights of the steps in increasing order.
Output Format
Output a single integer: the minimum number of moves if it is possible to reach the top step; otherwise, output .
5
0 1 2 3 6
7
Hint
Sample Explanation: Climb up steps consecutively, then retreat steps, and then jump directly to the top.
Constraints:
- For of the testdata, .
- For of the testdata, , and the height of each step does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号