제출 #1283919

#제출 시각아이디문제언어결과실행 시간메모리
1283919thirdGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
17 ms5132 KiB
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl '\n'
#define TASK ""
#define N 800005
#define LOG 17
using namespace std;

ll n, a[N], pf[N], sf[N];

signed main() {
   // freopen("test.inp", "r", stdin);
	//freopen("test.out", "w", stdout);
	//srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
   	cin >> n;
   	for (int i = 1; i <= n; i ++) {
   		cin >> a[i];
   	}
   	for (int i = 2; i <= n; i ++) {
   		pf[i] = pf[i - 1] + max(0LL, a[i - 1] + 1 - a[i]);
   	}
   	for (int i = n - 1; i >= 1; i --) {
   		sf[i] = sf[i + 1] + max(0LL, a[i + 1] - a[i] + 1);
   	}
   	ll ans = 1e18;
   	for (int i = 1; i <= n; i ++) {
   		ans = min(ans, max(pf[i], sf[i]));
   	}
   	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...