제출 #412976

#제출 시각아이디문제언어결과실행 시간메모리
412976OzyGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
31 ms5060 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define lli long long int #define debugsl(a) cout << #a << " = " << a << ", " #define debug(a) cout << #a << " = " << a << endl #define MAX 200000 lli n,a,res; lli arr[MAX+2]; lli pref[MAX+2],suf[MAX+2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; rep(i,1,n) cin >> arr[i]; //prefijo rep(i,2,n) { if (arr[i-1] >= arr[i]) pref[i] = arr[i-1] - arr[i] + 1; pref[i] += pref[i-1]; } //prefijo repa(i,n-1,1) { if (arr[i+1] >= arr[i]) suf[i] = arr[i+1] - arr[i] + 1; suf[i] += suf[i+1]; } res = 1ll<<62; rep(i,1,n) { a = max(pref[i], suf[i]); res = min(res,a); } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...