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>
#define ll long long
using namespace std;
int main()
{
int N; cin >> N;
vector<ll> arr(N);
for(int i = 0;i<N;++i) cin >> arr[i];
vector<ll> f(N,0),g(N,0); //f : for increasing numbers before i; g : for decreasing numbers after i (that are bigger than arr[i])
for(int i = 1;i<N;++i){
f[i] = f[i-1]+max(arr[i-1]-arr[i]+1,0ll);
}
for(int i = N-2;i>=0;--i){
g[i] = g[i+1]+max(arr[i+1]-arr[i]+1,0ll);
}
ll ans = 1e18;
for(int i = 0;i<N;++i){
//cout << f[i] << " " << g[i] << "\n";
ans = min(ans,max(f[i],g[i]));
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |