제출 #372709

#제출 시각아이디문제언어결과실행 시간메모리
372709SeDunionGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
15 ms364 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

ll A[N], b[N];

int main() { // fuck O(N) all my homies brute for O(N^2)
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> A[i];
	}
	ll ans = ll(1e18);
	for (int i = 1 ; i <= n ; ++ i) { // the highest point
		for (int j = 1 ; j <= n ; ++ j) {
			b[j] = A[j];
		}
		ll L = 0, R = 0; // the number of waterings of the left side and the right side
		for (int j = 1 ; j + 1 < i ; ++ j) {
			if (b[j + 1] < b[j] + 1) {
				L += b[j] + 1 - b[j + 1];
				b[j + 1] = b[j] + 1;
			}
		}
		for (int j = n ; j - 1 > i ; -- j) {
			if (b[j - 1] < b[j] + 1) {
				R += b[j] + 1 - b[j - 1];
				b[j - 1] = b[j] + 1;
			}
		}
		ll nL = 0, nR = 0;
		if (b[i - 1] + 1 > b[i] + R) {
			nL = b[i - 1] + 1 - b[i] - R;
		}
		if (b[i + 1] + 1 > b[i] + L) {
			nR = b[i + 1] + 1 - b[i] - L;
		}
		L += nL, R += nR;
		ans = min(ans, max(L, R));
	}
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...