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 main() {
int n;
cin>>n;
vector<int>vegetales(n);
for(int i=0;i<n;i++){
cin>>vegetales[i];
}
vector<int>a(n);
a[0]=0;
for(int i=1;i<n;i++){
a[i]=a[i-1]+max(0,vegetales[i-1]-vegetales[i]+1);
}
reverse(vegetales.begin(),vegetales.end());
vector<int>b(n);
b[0]=0;
for(int i=1;i<n;i++){
b[i]=b[i-1]+max(0,vegetales[i-1]-vegetales[i]+1);
}
int ans=INT_MAX;
reverse(b.begin(),b.end());
for(int i=0;i<n;i++){
ans=min(ans,max(a[i],b[i]));
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |