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 pb push_back
#define ll long long
#define s second
#define f first
#define int ll
using namespace std;
const int N = 200005;
ll a[N],pref[N],suff[N];
vector <int> v;
main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i=1;i<=n;i++)
cin>>a[i];
ll ans=1e18;
for (int i=1;i<=n;i++)
pref[i] = pref[i - 1] + max((ll)0,a[i - 1] - a[i] + 1);
for (int i = n; i >= 1; i--)
suff[i] = suff[i + 1] + max((ll)0,a[i + 1] - a[i] + 1);
for (int i=1;i<=n;i++)
ans = min(ans,max(pref[i],suff[i]));
cout<<ans;
}
Compilation message (stderr)
Main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main (){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |