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;
const int MAXN = 2e5+5;
ll arr[MAXN],f[MAXN],g[MAXN];
ll INF = 1e18;
int main()
{
int N; cin >> N;
for(int i = 1;i<=N;++i) cin >> 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;i>=0;--i){
g[i] = g[i+1]+max(arr[i+1]-arr[i]+1,0ll);
}
ll ans = INF;
for(int i = 1;i<=N;++i){
ans = min(max(f[i],g[i]),ans);
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |