CF1397B.Power Sequence
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's call a list of positive integers a0,a1,...,an−1 a power sequence if there is a positive integer c , so that for every 0≤i≤n−1 then ai=ci .
Given a list of n positive integers a0,a1,...,an−1 , you are allowed to:
- Reorder the list (i.e. pick a permutation p of {0,1,...,n−1} and change ai to api ), then
- Do the following operation any number of times: pick an index i and change ai to ai−1 or ai+1 (i.e. increment or decrement ai by 1 ) with a cost of 1 .
Find the minimum cost to transform a0,a1,...,an−1 into a power sequence.
输入格式
The first line contains an integer n ( 3≤n≤105 ).
The second line contains n integers a0,a1,...,an−1 ( 1≤ai≤109 ).
输出格式
Print the minimum cost to transform a0,a1,...,an−1 into a power sequence.
输入输出样例
输入#1
3 1 3 2
输出#1
1
输入#2
3 1000000000 1000000000 1000000000
输出#2
1999982505
说明/提示
In the first example, we first reorder {1,3,2} into {1,2,3} , then increment a2 to 4 with cost 1 to get a power sequence {1,2,4} .