Submission #381748

#TimeUsernameProblemLanguageResultExecution timeMemory
381748sofapudenGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms364 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n; cin >> n; vector<ll> v(n); for(auto &x : v)cin >> x; ll l = 1, r = n-2; ll ans = 0; while(l <= r){ while(l <= n-1 && v[l] > v[l-1])l++; while(r >= 0 && v[r] > v[r+1])r--; if(l > r)break; ll x = min(v[r+1]-v[r]+1,v[l-1]-v[l]+1); v[l-1]-=x; v[r+1]-=x; ans+=x; } if(abs(l-r) == 1)ans++; cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...