제출 #649844

#제출 시각아이디문제언어결과실행 시간메모리
649844ivazivaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 200010 long long n; long long niz[MAXN]; long long p[MAXN]; long long pref[MAXN],suf[MAXN]; int main() { cin>>n; for (long long i=1;i<=n;i++) cin>>niz[i]; p[1]=niz[1]; for (long long i=2;i<=n;i++) p[i]=niz[i]-niz[i-1]; for (long long i=1;i<=n;i++) { if (p[i]>0) pref[i]=pref[i-1]; else pref[i]=pref[i-1]+(p[i]*(-1)+1); } for (long long i=n;i>=1;i--) { if (p[i]<0) suf[i]=suf[i+1]; else suf[i]=suf[i+1]+p[i]+1; } long long maksi=1000000010; for (long long i=0;i<=n;i++) { maksi=min(maksi,max(pref[i],suf[i+1])); } cout<<maksi<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...