显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cmath>
#define N 2000000 + 7
using namespace std;
long long k,minn=999999999,order=0;
int a[N],l[N],L,R,n,i;
int lyh()
{
freopen("MrBB1.in","r",stdin);
freopen("MrBB1.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&a[i]),order+=abs(a[i]-i);
if(a[i]>=i)l[a[i]-i]++,L++;
if(a[i]<i)R++;}
if(!order)
{
printf("0 0\n");
return 0;
}
minn=order;
k=0;
for(i=1;i<n;i++)
{
L=L-l[i-1];
R=R+l[i-1];
order+=R-L-abs(a[n-i+1]-n-1)+abs(a[n-i+1]-1);
if(minn>order)k=i,minn=order;
l[a[n-i+1]+i-1]++;
L++;
R--;
}
printf("%lld %d\n",minn,k);
return 0;
}
int h=lyh();
int main(){;}