제출 #744794

#제출 시각아이디문제언어결과실행 시간메모리
744794Andrei_ierdnAGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
41 ms6952 KiB
#include <iostream> #include <iomanip> using namespace std; #define INF 1000000000000000LL long long n, i, a[200100], prefval[200100], sufval[200100], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } prefval[1] = 0; for (i = 2; i <= n; i++) { prefval[i] = prefval[i-1]; if (a[i] <= a[i-1]) { prefval[i] += (a[i-1] - a[i] + 1); } } sufval[n] = 0; for (i = n-1; i >= 1; i--) { sufval[i] = sufval[i+1]; if (a[i] <= a[i+1]) { sufval[i] += (a[i+1] - a[i] + 1);; } } ans = max(prefval[1], sufval[1]); for (i = 2; i <= n; i++) { ans = min(ans, max(prefval[i], sufval[i])); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...