Submission #1298631

#TimeUsernameProblemLanguageResultExecution timeMemory
1298631tminhGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
18 ms6712 KiB
#include "bits/stdc++.h"
using namespace std;

#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>


#define ep emplace_back
#define pb push_back
#define pf push_front


const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const ll oo = 1e18;

ll n, a[N], d[N], pre[N], suf[N];

inline void solve() {
	for (int i = 2; i <= n; ++i) d[i] = (a[i] - a[i - 1]);
	for (int i = 2; i <= n; ++i) pre[i] = pre[i - 1] + max(0ll, (1 - d[i]));
	for (int i = n; i >= 2; --i) suf[i] = suf[i + 1] + max(0ll, (d[i] + 1));
	ll ans = oo;
	
	for (int i = 1; i <= n; ++i) ans = min(ans, max(pre[i], suf[i + 1]));
		
	cout << ans;
	
}


inline void input() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    return solve();
}

int main() {
    if(fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    input();
    return 0;
}
//2911

Compilation message (stderr)

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