| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1281903 | LmaoLmao | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 16 ms | 4336 KiB | 
#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define vi vector<int>
using namespace std;
bool START_ALLOC;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}
const int MAX = 2e5 + 15;
int n;
int a[MAX];
ll pref[MAX], suff[MAX];
void solve(){
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 2; i <= n; i++){
        pref[i] = pref[i-1] + max(0, a[i-1] - a[i] + 1);
    }
    for(int i = n-1; i >= 1; i--){
        suff[i] = suff[i+1] + max(0, a[i+1] - a[i] + 1);
    }
    ll answer = LLONG_MAX;
    for(int i = 1; i <= n; i++) minimize(answer, max(pref[i], suff[i]));
    cout << answer << endl;
}
bool END_ALLOC;
signed main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);
    #define task "task"
    cerr << "[Static Memory : " << fixed << setprecision(2) << (((&END_ALLOC) - (&START_ALLOC)) / (1024.0 * 1024.0)) << "mb]\n";
    if(fopen(task".INP", "r")){
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    int t; t = 1; //cin >> t;
    while(t--) solve();
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
