Submission #942165

#TimeUsernameProblemLanguageResultExecution timeMemory
942165dsyzGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
20 ms7004 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MAXN (1000005) int main() { ios_base::sync_with_stdio(false);cin.tie(0); ll N; cin>>N; ll arr[N]; for(ll i = 0;i < N;i++){ cin>>arr[i]; } ll ans = 1e18; ll prefix[N]; ll Ldiff = 0; for(ll i = 0;i < N;i++){ if(i >= 1) Ldiff += max(0ll,(arr[i - 1] + 1) - arr[i]); prefix[i] = Ldiff; } ll suffix[N]; ll Rdiff = 0; for(ll i = N - 1;i >= 0;i--){ if(i < N - 1) Rdiff += max(0ll,(arr[i + 1] + 1) - arr[i]); suffix[i] = Rdiff; } for(ll split = 0;split < N;split++){ ll total = max(prefix[split],suffix[split]); ans = min(ans,total); } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...