제출 #373930

#제출 시각아이디문제언어결과실행 시간메모리
373930achibasadzishviliGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
36 ms5100 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll n,a[200005],pre[200005],suf[200005]; int main(){ ios::sync_with_stdio(false); cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; } for(int i=1; i<=n; i++){ pre[i] = pre[i - 1]; if(a[i] <= a[i - 1]) pre[i] += a[i - 1] - a[i] + 1; } ll ans = 100000000000000; for(int i=n; i>=1; i--){ suf[i] = suf[i + 1]; if(a[i] <= a[i + 1]) suf[i] += a[i + 1] - a[i] + 1; ans = min(ans , max(suf[i] , pre[i])); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...