Submission #647823

#TimeUsernameProblemLanguageResultExecution timeMemory
647823ymmGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
31 ms4636 KiB
#include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x) #define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x) typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll , ll > pll; using namespace std; const int N = 200'010; int a[N]; int d1[N], d2[N]; int n; int main() { cin.tie(0) -> sync_with_stdio(false); cin >> n; Loop (i,0,n) cin >> a[i]; Loop (i,0,n-1) d1[i] = max(0, a[i] - a[i+1] + 1); Loop (i,1,n) d2[i] = max(0, a[i] - a[i-1] + 1); ll s1=0, s2=0; Loop (i,1,n) s2 += d2[i]; ll ans = s2; Loop (i,1,n) { s1 += d1[i-1]; s2 -= d2[i]; ans = min(ans, max(s1, s2)); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...