Submission #391561

#TimeUsernameProblemLanguageResultExecution timeMemory
391561bayemirovGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
33 ms6268 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const int N = 3e5; const ll INF = 1e18; int n, a[N]; ll p[N], s[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; int d = a[i] - a[i - 1]; p[i] = p[i - 1] + max(0, 1 - d); } for (int i = n - 1; i >= 1; i--) { int d = a[i + 1] - a[i]; s[i] = s[i + 1] + max(0, 1 + d); } ll ans = INF; for (int i = 1; i <= n; i++) { ans = min(ans, max(p[i], s[i])); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...