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;
int h[201000];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>h[i];
}
int mini = INT_MAX;
for(int i=0;i<n;i++){
//peak = i position
int x[n];x[0]=0;
for(int j=1;j<=i;j++){
x[j] = x[j-1] + max(h[j-1]-h[j]+1,0);
}
int y[n];y[n-1]=0;
for(int j=n-2;j>=i;j--){
y[j] = y[j+1] + max(h[j+1]-h[j]+1,0);
}
int maxy = max(x[i],y[i]);
if(mini>maxy)mini = maxy;
}
cout<<mini;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |