Submission #574258

#TimeUsernameProblemLanguageResultExecution timeMemory
574258benson1029Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
82 ms6944 KiB
#include<bits/stdc++.h> using namespace std; int n; long long a[200005]; long long ans[200005], ans2[200005]; int main() { cin >> n; for(int i=1; i<=n; i++) { cin >> a[i]; } for(int i=n; i>=1; i--) { a[i] -= a[i-1]; } for(int i=1; i<=n; i++) { ans[i] = ans[i-1]; if(a[i] <= 0) { ans[i] += 1 - a[i]; } } for(int i=n-1; i>=0; i--) { ans2[i] += ans2[i+1]; if(a[i+1] >= 0) { ans2[i] += 1 + a[i+1]; } } long long o = 1e18; for(int i=0; i<=n; i++) o = min(o, max(ans[i], ans2[i])); cout << o << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...