Submission #527698

#TimeUsernameProblemLanguageResultExecution timeMemory
527698knightron0Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
26 ms6892 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second #define clr(a, x) memset(a, x, sizeof(a)) #define dbg(x) cout<<"("<<#x<<"): "<<x<<endl; #define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl; #define all(v) v.begin(), v.end() #define lcm(a, b) (a * b)/__gcd(a, b) #define int long long int #define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl; #define endl '\n' #define float long double const int MOD = 1e9 + 7; const int INF = 2e15; const int MAXN = 1e5 + 5; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n; cin>>n; int a[n+4]; for(int i=0;i<n;i++){ cin>>a[i]; } int pref[n+4], suff[n+4]; pref[0] = suff[n-1] = 0; for(int i=1;i<n;i++){ pref[i] = pref[i-1]; pref[i] += max((int)0, a[i-1]-a[i]+1); } for(int i=n-2;i>=0;i--){ suff[i] = suff[i+1]; suff[i] += max((int)0, a[i+1]-a[i]+1); } int ans = LLONG_MAX; for(int i=0;i<n;i++){ ans = min(ans, max(pref[i], suff[i])); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...