Submission #1331591

#TimeUsernameProblemLanguageResultExecution timeMemory
1331591tkm_algorithmsGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
18 ms484 KiB

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using P = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define sz(x) (int)x.size()
const char nl = '\n';
const int mod = 998244353;
const int inf = 1e9*2e3+4e6;

void solve() {
	int n; cin >> n;
	vector<int> a(n), b;
	for (auto &i: a)cin >> i;
	b = a;
	
	int res = inf;
	rep(i, 0, n) {
		if(i)rep(j, 1, i+1) // increases till i
			//sm += max(a[j], a[j-1]+1)-a[j];
			a[j] = max(a[j], a[j-1]+1);
		if(i!=n-1)rep(j, n-1, i)
			//sm += max(a[j], a[j+1]+1)-a[j];
			a[j] = max(a[j], a[j+1]+1);
		vector<int> c = a;
		rep(j, 0, n)c[j] -= b[j];
		int sm = c[0];
		rep(j, 1, n)sm += c[j]-min(c[j], c[j-1]);
		res = min(res, sm); a = b;
		//if (sm == 2) {
			//for (auto j: a)cout << j << " ";
			//cout << nl; 
		//}
	}
	cout << res << nl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...