Submission #1150443

#TimeUsernameProblemLanguageResultExecution timeMemory
1150443henriessGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n;cin >> n; vector<long long> A(n); for(int i = 0;i<n;i++){ cin >> A[i]; } //sequence has to be increasing then decreasing vector<long long> p(n); vector<long long> s(n); p[0] = A[0]; //I can water a consecutive segment for(int i = 1;i<n;i++){//has to be increasing p[i] = max(A[i],p[i-1] + 1); } s[n-1] = A[n-1]; for(int i = n-2;i>=0;i--){ s[i] = max(A[i],s[i+1] + 1); } vector<long long> B(n); B[0] = 0; for(int i = 1;i<n;i++){ B[i] = B[i-1] + max(0LL, p[i] - A[i]); } //B[i] represents the costs vector<long long> Z(n); Z[n-1] = 0; for(int i = n-2;i>=0;i--){ Z[i] = Z[i+1] + max(0LL,s[i] - A[i]); } long long ans = LLONG_MAX; for(int i = 0;i<n;i++){ ans = min(ans,max(Z[i],B[i])); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...