cswork / OA打开练习工作台

AmazonOA #27

Get Minimum Health (Armor Round)

估计简单可在线判题

考点(AI 标注)贪心调度原地数组

You take each round of damage in order, and your health must always stay strictly greater than 0. In one round you may use the armor, which blocks min(armor, damage this round) points of damage. Find the minimum initial health.

输入格式

The first line contains n armor (1≤n≤100000, 1≤armor≤10⁹); the second line contains n damage values (1..10⁹).

输出格式

Output a single integer, the answer.

样例 1

输入:

4 5
1 2 6 7

输出:

12

样例 2

输入:

1 9
1

输出:

1

样例 3

输入:

2 1
5 5

输出:

10

样例说明

Example 1: the total damage is 16 and the armor blocks 5, leaving 11 damage, so the initial health must be 12. Example 2: the armor blocks the only 1 point of damage, so an initial health of 1 is enough. Example 3: after blocking 1, the total damage is 9, so 10 is needed.