← 返回 amazon 的题目列表Minimum Initial Health Points Required to Clear the Game
类型:online_judge
amazon
In a game, a player needs to pass through n levels sequentially, and each level consumes a certain amount of health points power[i]. The player's health points must always remain positive. The player can use armor once during any level, which can reduce damage by up to armor points, but cannot exceed the damage of that level power[i]. Calculate the minimum initial health points needed for the player to clear the game.
Input:
n = 5
power = [3, 7, 2, 5, 10]
armor = 6
Output:
15
Constraints:
1 <= n <= 10^5
1 <= power[i] <= 10^4
0 <= armor <= 10^4
The test cases guarantee that there is at least one valid solution.
Example
Input
5
3 7 2 5 10
6