← 返回 amazon 的题目列表Minimum Initial Health to Survive Game Levels
类型:online_judge
amazon
A player needs to pass through multiple rounds of a game, each consuming a certain amount of health points. The health points must always remain greater than 0. Design a function to calculate the minimum initial health points required for the player to clear all levels. The input is an array where each element represents the health points consumed by that level. The array length is n (1 <= n <= 10^5) and each element's absolute value does not exceed 10^4. The output is the minimum initial health points. Example: Input: [2, -3, 3, 5, -10, 2] Output: 7
Example
Input
[2, -3, 3, 5, -10, 2]