← 返回 amazon 的题目列表Minimum Initial Health With One Armor Use
类型:online_judge
amazon
Minimum Health Requirement
In a game, a player needs to keep their health above zero over several rounds. Each round, the player takes a certain amount of damage. The player can choose to use an armor once to completely absorb the damage of one round. Given an integer array damage, where damage[i] represents the damage taken in the i-th round, determine the minimum initial health required for the player to survive using the best strategy.
Input
damage: an integer array representing the damage taken each round
Output
An integer representing the minimum initial health required for the player
Example
Input: [1, 2, 3, 4]
Output: 7
Explanation: Use armor in the third round to absorb 3 damage. Hence, need to only suffer 1+2+4=7 damage.
Constraints
1 ≤ len(damage) ≤ 10^5
1 ≤ damage[i] ≤ 10^4
Example
Input
[1, 2, 3, 4]