Submission #1230004

#TimeUsernameProblemLanguageResultExecution timeMemory
1230004antromancapGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
14 ms4964 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; long long f[N], g[N], a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) f[i] = f[i - 1] + max(0LL, a[i - 1] - a[i] + 1); for (int i = n; i; i--) g[i] = g[i + 1] + max(0LL, a[i + 1] - a[i] + 1); long long res = 1e18; for (int i = 1; i <= n; i++) { res = min(res, max(f[i], g[i])); } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...