Start: Feb, 21, 2019 12:00:00
2018-2019 ACM集训队冬季集训第二次考核
End: Feb, 21, 2019 17:00:00
Time elapsed:
Time remaining:

Problem_ID: B
Result: Accepted
Time: 73ms
Memory: 3280kB
Author: 2017212212145
In contest: 1261

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define MAXN 100010
#define ll long long
int n;
long long a[MAXN],sum[MAXN];
long long cnt,ans;
int main()
{
	scanf("%d",&n);
	ans=1000000000000;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		if(i<=(n+1)/2)
			a[i]=a[i]-i+1;
		else
			a[i]=a[i]-n+i;
	}
	sort(a+1,a+n+1);
	sum[0]=0;
	for(int i=1;i<=n;++i)
		sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=n;++i)
	{
		if(a[i+1]!=a[i])
		{
			cnt=i*a[i]-2*sum[i]+sum[n]-(n-i)*a[i];
			ans=min(cnt,ans);
		}
	}
	printf("%lld\n",ans);
}