Submission #601511

#TimeUsernameProblemLanguageResultExecution timeMemory
601511pakhomoveeGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
33 ms6904 KiB
#include <iostream> #include <vector> #include <algorithm> #include <random> #include <iomanip> #include <cassert> #include <deque> #include <functional> #include <set> #include <queue> #include <map> using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); for (int& i : a) cin >> i; int ans = 1e18; vector<int> pref(n, 0); vector<int> suff(n, 0); for (int i = 1; i < n; ++i) { pref[i] = pref[i - 1] + max(0ll, a[i - 1] - a[i] + 1); } for (int i = n - 2; i >= 0; --i) { suff[i] = suff[i + 1] + max(0ll, a[i + 1] - a[i] + 1); } for (int i = 0; i < n; ++i) { ans = min(ans, max(pref[i], suff[i])); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...