This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int lld;
#define INF 100000000000000000
lld dist(lld a, lld b){
if(a<b)return b-a;
return a-b;
}
int main(){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)cin>>arr[i];
lld ans=INF;
for(int bottom=0;bottom<n;bottom++){
lld can=0;
int b[n];
for(int i=0;i<n;i++)b[i]=arr[i]+dist(i,bottom);
sort(b,b+n);
int mid=n/2;
lld height=max(1+max(bottom,n-bottom-1),b[mid]);
for(int i=0;i<n;i++)can+=dist(height,b[i]);
ans=min(ans,can);
//cout<<can<<" "<<height<<endl;
}cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |