Submission #704645

#TimeUsernameProblemLanguageResultExecution timeMemory
704645StickfishGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
90 ms3020 KiB
#include <iostream> using namespace std; using ll = long long; const int MAXN = 2e5 + 123; int a[MAXN]; signed main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = n - 1; i > 0; --i) a[i] -= a[i - 1]; ll ans = 0; ll rval = 0; for (int i = 1; i < n; ++i) rval += max(0, a[i] + 1); ll lval = 0; ans = rval; for (int i = 1; i < n; ++i) { rval -= max(0, a[i] + 1); lval += max(0, -a[i] + 1); ans = min(ans, max(rval, lval)); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...