제출 #649891

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