Submission #954830

#TimeUsernameProblemLanguageResultExecution timeMemory
954830sandry24Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second void solve(){ int n; cin >> n; vector<ll> a(n), up(n), down(n); for(int i = 0; i < n; i++) cin >> a[i]; up[0] = down[n-1] = 0; for(int i = 1; i < n; i++){ ll curr = max(a[i-1]+1, a[i]); up[i] = up[i-1] + curr - a[i]; } for(int i = n-2; i >= 0; i--){ ll curr = max(a[i+1]+1, a[i]); down[i] = down[i+1] + curr - a[i]; } ll ans = down[0]; for(int i = 1; i < n; i++){ ll left_elem = a[i-1] + up[i-1]; ll right_elem = a[i] + down[i]; ll curr = max(left_elem, right_elem); ans = min(ans, max(up[i-1], down[i]) + curr - right_elem); } cout << ans << '\n'; } int main(){ // freopen("hex.in", "r", stdin); // freopen("hex.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...