제출 #1179996

#제출 시각아이디문제언어결과실행 시간메모리
1179996anteknneGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
13 ms5004 KiB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false

const int MAXN = 200 * 1000;
ll a[MAXN];

ll r[MAXN];
ll m[MAXN];

int main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }

    for (int i = 1; i < n; i ++) {
        r[i] = r[i - 1] + max(0LL, a[i - 1] - a[i] + 1LL);
    }

    for (int i = n - 2; i >= 0; i --) {
        m[i] = m[i + 1] + max(0LL, a[i + 1] - a[i] + 1LL);
    }

    /*for (int i = 0; i < n; i ++) {
        cout << r[i] << " " << m[i] << "\n";
    }*/



    ll wyn = LLONG_MAX;
    for (int i = 0; i < n; i ++) {
        wyn = min(wyn, max(r[i], m[i]));
    }

    cout << wyn << "\n";

    return 0;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...