제출 #1184081

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

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000'000'000'000'000'000LL;
const int II = 2'000'000'000;
const ll M = 1000'000'007LL;
const int N = 1000'007;
int tab[N], m1[N], m2[N];
ll s1[N], s2[N];

void Solve()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> tab[i];
    for(int i = 1; i <= n; ++i)
    {
        m1[i] = max(tab[i], m1[i - 1] + 1);
        s1[i] = s1[i - 1];
        s1[i] += max(0, (m1[i] - tab[i]) - (m1[i - 1] - tab[i - 1])); 
    }
    for(int i = n; i >= 1; --i)
    {
        m2[i] = max(tab[i], m2[i + 1] + 1);
        s2[i] = s2[i + 1];
        s2[i] += max(0, (m2[i] - tab[i]) - (m2[i + 1] - tab[i + 1]));
    }
    ll ans = I;
    for(int i = 1; i <= n; ++i)
        ans = min(ans, max(s1[i], s2[i]));
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t; cin >> t;
    //while(t--)
        Solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...