Submission #717996

#TimeUsernameProblemLanguageResultExecution timeMemory
717996KalashnikovGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
25 ms4356 KiB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

int a[N];
ll suf[N], pref[N];

void solve(int tc) {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	for(int i = n-1; i >= 1; i --) {
		suf[i] = suf[i+1];
		if(a[i] <= a[i+1]) {
			suf[i] += a[i+1]-a[i]+1;
		}
	}
	for(int i = 2; i <= n; i ++) {
		pref[i] = pref[i-1];
		if(a[i] <= a[i-1]) {
			pref[i] += a[i-1]-a[i]+1;
		}
	}
	ll res = INF;
	for(int i = 1; i <= n; i ++) {
		res = min(res , max(pref[i], suf[i]));
	}
	cout << res;
}
/*
*/
main() {
    ios;
    int tt = 1 , tc = 0;
    // cin >> tt;
    while(tt --) {
        solve(++tc);
    }
    return 0;
}

Compilation message (stderr)

Main.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...