제출 #493830

#제출 시각아이디문제언어결과실행 시간메모리
493830i_am_noobGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
26 ms6952 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...