제출 #1180271

#제출 시각아이디문제언어결과실행 시간메모리
1180271nekolieGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
19 ms5132 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; long long a[n], suma[n][2], odp = 1000000000000000000; for (int i = 0; i < n; i++) cin >> a[i]; suma[0][0] = suma[n-1][1] = 0; for (int i = 1; i < n; i++) suma[i][0] = suma[i-1][0] + ((a[i-1] >= a[i]) ? a[i-1]-a[i]+1 : 0); for (int i = n-2; i >= 0; i--) suma[i][1] = suma[i+1][1] + ((a[i] <= a[i+1]) ? a[i+1]-a[i]+1 : 0); for (int i = 0; i < n; i++) odp = min(odp,max(suma[i][0],suma[i][1])); cout << odp << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...