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;
#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pii pair<int,int>
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define inf 1000'000'000'000'000'000
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ": " << #__VA_ARGS__ << "- ",_do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ... S> void _do(T x, S ...y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=200005;
int n,a[maxn],cnt1[maxn],cnt2[maxn],res=inf;
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n;
rep(n) cin >> a[i];
cnt1[0]=0;
rep(n-1) cnt1[i+1]=cnt1[i]-min(0ll,a[i+1]-a[i]-1);
cnt2[n-1]=0;
rep3(i,n-2,0) cnt2[i]=cnt2[i+1]+max(0ll,a[i+1]-a[i]+1);
rep(n) res=min(res,max(cnt1[i],cnt2[i]));
cout << res << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |