#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define dd(x) cout<<#x<<" is "<<x<<endl;
typedef pair<int,int> pii;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
int a[n+2]= {};
for(int i=1; i<=n; i++) cin>>a[i];
int ans = LLONG_MAX;
for(int k=1; k<=n; k++){ //k is the tallest guy
int x=0, y=0;
for(int i=1; i<=k; i++){
if(a[i] <= a[i-1]) x+= (a[i-1]-a[i]+1);
}
for(int i=k; i<=n; i++){
if(a[i] <= a[i+1]) y+= (a[i+1]-a[i]+1);
}
ans = min(ans,max(x,y));
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |