#P8775. [蓝桥杯 2022 省 A] 青蛙过河
[蓝桥杯 2022 省 A] 青蛙过河
Problem Description
A little frog lives by a river and wants to go to the school on the other side to study. The frog plans to jump on stones in the river to reach the opposite bank.
The stones in the river are arranged in a straight line. Each jump must land on a stone or on a bank. Each stone has a height. Every time the frog jumps from a stone, the height of that stone decreases by . When a stone’s height decreases to , the frog can no longer land on that stone (it is allowed that after some jump, the stone’s height becomes ).
The frog needs to attend school for days, so it must make round trips, i.e. cross the river times. If the frog has a jumping ability , it can jump a distance of at most .
Find the minimum jumping ability required so that the frog can use these stones to finish attending school for days.
Input Format
The first line contains two integers , representing the width of the river and the number of days the frog needs to go to school. Note that is the actual number of crossings.
The second line contains non-negative integers . Here, means there is a stone of height at distance from the frog’s home bank, and means there is no stone at that position.
Output Format
Output one line containing one integer, representing the minimum jumping ability the frog needs.
5 1
1 0 1 0
4
Hint
Sample Explanation
Since there are only two stones with height , each direction of the round trip can only use one stone. The distance between the first stone and the opposite bank is . If the frog’s jumping ability is , it cannot meet the requirement. Therefore, the frog needs a minimum jumping ability of .
Constraints and Conventions
For of the testdata, .
For of the testdata, .
For all testdata, , , .
Lanqiao Cup 2022 Provincial Contest A Group, Problem F.
Translated by ChatGPT 5