제출 #832983

#제출 시각아이디문제언어결과실행 시간메모리
832983OzyGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
22 ms6944 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define lli long long int #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #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 pll pair<lli,lli> #define MAX 200000 lli arr[MAX+2],izq[MAX+2],der[MAX+2]; lli res,a,n; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; rep(i,1,n) { cin >> arr[i]; if(i==1) continue; der[i] = der[i-1]; if (arr[i] <= arr[i-1]) der[i] += arr[i-1] - arr[i] + 1; } res = -1; repa(i,n,1){ if (i < n) { izq[i] = izq[i+1]; if (arr[i+1] >= arr[i]) izq[i] += arr[i+1] - arr[i] + 1; } a = max(der[i],izq[i]); if (res == -1 || a < res) res = a; } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...