Submission #530289

#TimeUsernameProblemLanguageResultExecution timeMemory
530289Tw_28e7Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms204 KiB
#include <bits/stdc++.h>

using namespace __gnu_cxx;
using namespace std;

#define LL long long
#define pLL pair<long long, long long>
#define F first
#define S second
#define pb push_back
#define rz resize
#define all(x) x.begin(), x.end()
void Star_Brust_Stream()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return;
}
const LL INF = 1e18;
const LL mod = 1e9 + 7;
LL f(LL a, LL b, LL m)
{
    LL c = 1;
    for (; b > 0; b >>= 1)
    {
        if (b & 1)
        {
            c = (c * a) % m;
        }
        a = (a * a) % m;
    }
    return c % m;
}
LL m(LL a, LL b)
{
    a += ((-a / b) + 2) * b;
    return a % b;
}

int main()
{
    Star_Brust_Stream();
    LL n;
    cin >> n;
    vector<LL> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    LL ans = 1e18;
    for (int i = 0; i < n; i++)
    {
        LL cnt = 0;
        for (int j = 0; j < i; j++)
        {
            if (v[j] >= v[j + 1])
            {
                cnt += (v[j] - v[j + 1] + 1);
            }
        }
        v[i] += cnt;
        for (int j = i; j < n; j++)
        {
            if (v[j] <= v[j + 1])
            {
                cnt += (v[j + 1] - v[j] + 1);
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    // system("pause");
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...