Submission #1056131

#TimeUsernameProblemLanguageResultExecution timeMemory
1056131SalihSahinGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
24 ms7128 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define double long double using namespace std; const int mod = 1e9 + 7; const int N = 2e5 + 5; int32_t main(){ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin>>n; vector<int> a(n); for(int i = 0; i < n; i++){ cin>>a[i]; } vector<int> dp1(n+1), dp2(n+1); dp1[1] = 0; for(int i = 1; i < n; i++){ dp1[i+1] = dp1[i] + max(0LL, a[i-1] + 1 - a[i]); } dp2[n] = 0; for(int i = n-2; i >= 0; i--){ dp2[i+1] = dp2[i+2] + max(0LL, a[i+1] + 1 - a[i]); } int ans = mod * mod; for(int i = 1; i <= n; i++){ ans = min(ans, max(dp1[i], dp2[i])); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...