Submission #1357500

#TimeUsernameProblemLanguageResultExecution timeMemory
1357500pqhxappleGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b)        for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b)       for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, n)           for (int i = (0), _n = (n); i < _n; ++i)
#define MASK(x)             (1LL << (x))
#define ON(mask, i)         (((mask) >> (i)) & (1LL))
#define ALL(x)              begin(x), end(x)
#define el                  cout << '\n'

template <class X, class Y> inline bool maximize(X &x, const Y &y) { return (x < y) ? x = y, 1 : 0; }
template <class X, class Y> inline bool minimize(X &x, const Y &y) { return (x > y) ? x = y, 1 : 0; }

constexpr int MAXN = 2e5 + 10;
int n;
int a[MAXN], b[MAXN];
long long pref[MAXN], suff[MAXN];

void load_input(void)
{
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
}

void prepare(void)
{
    FOR(i, 2, n)    pref[i] = pref[i - 1] + max(0, a[i - 1] - a[i] + 1);
    FORD(i, n - 1, 1)   suff[i] = suff[i + 1] + max(0, a[i + 1] - a[i] + 1);
}

void process(void)
{
    prepare();

    long long res = 1e18;
    FOR(i, 1, n) minimize(res, pref[i] + suff[i]);

    cout << res << '\n';
}

signed main(void)
{
    cin.tie(nullptr)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);

    #define task "B"
    if (fopen(task".INP", "r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

    int testcase = 1;
    while (testcase--)
    {
        load_input();
        process();
    }

    return 1 ^ 1;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...