Submission #1291531

#TimeUsernameProblemLanguageResultExecution timeMemory
1291531tunademayoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
18 ms4336 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define FOR(i, a, b) for(int i = a ; i <= b ; i++)
#define FORD(i, a, b) for(int i = a ; i >= b ; i--)
#define REP(i, a, b) for(int i = a ; i < b ; i++)

const bool Multitest = 0, Local = 0;

const int N = 2e5 + 10;

int a[N], n;

ll ans = 1e18, pref[N], suff[N];

void work()
{
    cin >> n;

    FOR(i, 1, n) cin >> a[i];
    FOR(i, 2, n)
    {
        if(a[i] < a[i - 1] + 1)
        {
            pref[i] += a[i - 1] + 1 - a[i];
        }
        pref[i] += pref[i - 1];
    }

    FORD(i, n - 1, 1)
    {
        if(a[i] < a[i + 1] + 1)
        {
            suff[i] += a[i + 1] + 1 - a[i];
        }
        suff[i] += suff[i + 1];
    }

    FOR(i, 1, n) ans = min(ans, max(suff[i], pref[i]));

    cout << ans;
}

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

    int q = 1;

    if(Local && fopen("code.inp", "r"))
    {
        freopen("code.inp", "r", stdin);
        freopen("code.ans", "w", stdout);
    }

    if(Multitest)   cin >> q;

    while(q--) work();
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen("code.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen("code.ans", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...