AmazonOA #232
Get Minimum Value
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
Pass the levels in order; level i deducts power[i] health, and health must stay strictly greater than 0 at all times. Armor may be used on at most one level to cancel min(armor,power[i]) damage. Find the minimum initial health.
Input
The first line contains n armor; the second line contains the damage values. 1≤n≤100000, 1≤damage,armor≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
4 5
1 2 6 7
Output:
12
Example 2
Input:
3 1
1 2 3
Output:
6
Example 3
Input:
1 10
5
Output:
1
Example notes
The answers are 12, 6 and 1. Even if all damage is blocked, at least 1 health is still required.
Editorial
Loading solution…