cswork / OA打开练习工作台

AmazonOA #303

Minimum Starting Health to Win the Game

估计中等可在线判题

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

You take the damage in the power array in order, and after every round your health must be strictly greater than 0. The armor can be used at most once; it reduces that round's damage by min(armor,power[i]) and does not restore health. Find the minimum initial health.

输入格式

The first line contains n armor and the second line contains power. The original bounds are 1≤n≤100000, 1≤power[i],armor≤10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

4 4
2 7 4 3

输出:

13

样例 2

输入:

1 10
1

输出:

1

样例 3

输入:

2 1
4 4

输出:

8

样例说明

The answers are 13, 1 and 8. In the second example all the damage can be blocked, but the initial health must still be at least 1.