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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n; cin>>n;
vector<ll> x;
for(int i=0;i<n;i++){
ll a; cin>>a;
x.push_back(a);
}
ll res=1e14+1;
for(int i=0;i<n;i++){
ll ac=0;
vector<ll> y=x;
ll c=0;
for(int j=1;j<=i;j++){
if(y[j]<=y[j-1]){
ac+=(y[j-1]-y[j])+1;
c+=(y[j-1]-y[j])+1;
}
}
y[i]+=ac;
for(int j=i+1;j<n;j++){
if(y[j-1]<=y[j]){
c+=(y[j]-y[j-1])+1;
ac=0;
y[j-1]=y[j]+1;
}
if(y[j]+ac>=y[j-1]){
ac=abs(y[j]-y[j-1])-1;
}
y[j]+=ac;
}
res=min(res,c);
}
cout<<res<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |