Submission #494795

#TimeUsernameProblemLanguageResultExecution timeMemory
494795ahmeterenGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
32 ms7116 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif long long n, cevap = 1e16; cin >> n; vector<long long> vec(n + 2), prefix(n + 1), suffix(n + 1); for(int i = 1; i <= n; i++) cin >> vec[i]; for(int i = 2; i <= n; i++) { prefix[i] = prefix[i - 1]; prefix[i] += max(0LL, (vec[i - 1] + 1) - vec[i]); } for(int i = n - 1; i > 0; i--) { suffix[i] = suffix[i + 1]; suffix[i] += max(0LL, (vec[i + 1] + 1) - vec[i]); } prefix[1] = suffix[n] = 0; for(int i = 1; i <= n; i++) { cevap = min(cevap, max(prefix[i], suffix[i])); } cout << cevap << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...