// created : 2026/02/01 15:06:19
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
void solve()
{
int n;
cin >> n;
vector<int> vt;
for (int i = 0; i < n; i++)
{
int x; cin >> x;
vt.pb(x);
}
int best = LLONG_MAX;
for (int i = 0; i < n; i++)
{
int x = 0;
vector<int> vt2 = vt;
while (true)
{
vector<int> vt3;
bool ok2 = false;
for (int j = 1; j < i; j++)
{
if (vt2[j - 1] >= vt2[j])
{
vt3.pb(j);
ok2 = true;
}
}
for(int j = i; j < n - 1; j++) {
if(vt2[j] <= vt2[j + 1]) {
vt3.pb(j);
ok2 = true;
}
}
if(!ok2) {
break;
}
for(int j = 0; j < vt3.size() - 1; j++) {
if(vt3[j] + 1 == vt3[j + 1]) {
while(j + 1 < vt3.size() and vt3[j] + 1 == vt3[j + 1]) {
j++;
}
x++;
}
else {
x++;
}
}
for(auto &d : vt3) {
vt2[d]++;
}
if(vt3.size() == 1) {
x++;
}
}
for(int i = 0; i < n - 1; i++) {
if(vt2[i] == vt2[i + 1]) {
vt2[i]++;
x++;
}
}
best = min(best, x);
}
cout << best << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |