Submission #954830

# Submission time Handle Problem Language Result Execution time Memory
954830 2024-03-28T16:42:52 Z sandry24 Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
0 / 100
0 ms 348 KB
#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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -