HearthStone
시간 제한1초메모리 제한2048 MB
미니언들의 체력을 1씩 바꿔, 한 번의 Defile 시전으로 모든 미니언을 처치하는 최소 변경 횟수를 구한다.
문제
Alice loves playing HearthStone! She loves the hero class of Warlock, who can cast the spell named Defile.
When cast, Defile deals unit of damage to the health of all minions. If any minion dies, Defile will be cast again automatically. Importantly, if two or more minions die simultaneously, it still causes a single Defile cast. That, in turn, may kill other minions, causing Defile to be cast again, and so on.
The health of each minion is a nonnegative integer. A minion dies when their health becomes zero. If a minion dies, it will disappear. It will not die twice.
Now there are minions. Before casting Defile, Alice can make zero or more steps. In each step, Alice changes a single minion's health by one. That is to say, if the health of a minion is , Alice can change it to or .
Alice wants to know the minimum number of steps such that, after these steps, she can cast a single Defile to kill all the minions.
입력
The first line contains a single integer ().
The next line contains integers (), the health of the minions.
출력
Print one integer: the minimum number of steps before Alice can cast a single Defile to kill all the minions.