HearthStone
Time limit1sMemory limit2048 MB
Given n minion health values, find the fewest unit changes so that one Defile cast chains into killing every minion.
- Level
Medium7 of 10
- Topics
- Sorting, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Alice loves playing HearthStone. She likes the Warlock hero class, which can cast the spell Defile. When cast, Defile deals unit of damage to the health of all minions. If any minion dies, Defile is cast again automatically. If two or more minions die at the same time, Defile is still cast only once. That cast may kill other minions, which causes Defile to be cast again, and so on. The health of each minion is a nonnegative integer. A minion dies when its health becomes zero. When a minion dies, it disappears and does not die twice. There are minions. Before casting Defile, Alice can take zero or more steps. In each step, Alice changes the health of one minion by one. If a minion has health , Alice can change it to or . Alice wants to find the minimum number of steps needed so that she can cast Defile once and kill all the minions.
Input
The first line contains a single integer (). The next line contains integers (), the health of the minions.
Output
Print one integer: the minimum number of steps before Alice can cast a single Defile to kill all the minions.