HearthStone

시간 제한1초메모리 제한2048 MB

요약
미니언들의 체력을 1씩 바꿔, 한 번의 Defile 시전으로 모든 미니언을 처치하는 최소 변경 횟수를 구한다.
난이도

어려움10점 중 8점

유형
수학, 그리디, 구현, 정렬
정답자
아직 제출이 없습니다

문제

Alice loves playing HearthStone! She loves the hero class of Warlock, who can cast the spell named Defile.

When cast, Defile deals 11 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 nn 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 xx, Alice can change it to x−1x-1 or x+1x+1.

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 nn (1≤n≤1061 \leq n \leq 10^6).

The next line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_i≤1061 \leq a\_i \leq 10^6), the health of the nn minions.

출력

Print one integer: the minimum number of steps before Alice can cast a single Defile to kill all the minions.

예제1

  1. 예제 1

    입력
    6
    4 6 8 9 2 4
    
    예상 출력
    12