Submission #1331593

#TimeUsernameProblemLanguageResultExecution timeMemory
1331593tkm_algorithmsGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
19 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;

vector<int> a, b;
int n; 

void inc(int x) {
	if (x)
		rep(j, 1, x+1)
			a[j] = max(a[j], a[j-1]+1);
}

void dec(int x) {
	if(x!=n-1)
		rep(j, n-1, x)
			a[j] = max(a[j], a[j+1]+1);
}

int cost() {
	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]);
	return sm;
}

void solve() {
	cin >> n;
	a.resize(n);
	for (auto &i: a)cin >> i;
	b = a;
	
	dec(0);
	int res = cost(); a = b;
	rep(i, 0, n) {
		inc(i); dec(i);
		res = min(res, cost()); a = b;
	}
	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...