제출 #957477

#제출 시각아이디문제언어결과실행 시간메모리
957477AcanikolicGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms528 KiB
#include <bits/stdc++.h>
		 				 
#define pb push_back 
		
#define F first
		 
#define S second

#define int long long 
		 		 
using namespace std;
		 
const int N = 1e5 + 10;
		 
const int mod = 1e9 + 7; 
 
const int inf = 2e9 + 1;
 		 	 	 		 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	
	int n;
	cin >> n;
	vector<int>a(n + 1),pref(n + 1),suf(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if(i > 1) {
			int diff = a[i] - a[i - 1] - 1;
			diff *= -1;
			pref[i] = pref[i - 1] + max(0ll,diff);
		}
	}
	for(int i = n - 1; i >= 1; i--) {
		int diff = a[i] - a[i + 1] - 1;
		diff *= -1;
		suf[i] = suf[i + 1] + max(0ll,diff);
	}
	int res = inf;
	for(int i = 1; i <= n; i++) res = min(res,max(pref[i],suf[i]));
	cout << res;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...