This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N;
cin>>N;
ll arr[N], A[N];
for(ll i = 0;i < N;i++){
cin>>arr[i];
A[i] = arr[i];
}
ll ans = 1e18;
for(ll split = 0;split < N;split++){
ll total = 0;
vector<ll> Ldiff,Rdiff;
for(ll i = 1;i <= split;i++){
total += max(0ll,(arr[i - 1] + 1) - arr[i]);
Ldiff.push_back(max(0ll,(arr[i - 1] + 1) - arr[i]));
arr[i] = max(arr[i],arr[i - 1] + 1);
}
for(ll i = N - 2;i >= split;i--){
total += max(0ll,(arr[i + 1] + 1) - arr[i]);
Rdiff.push_back(max(0ll,(arr[i + 1] + 1) - arr[i]));
arr[i] = max(arr[i],arr[i + 1] + 1);
}
sort(Ldiff.begin(),Ldiff.end(),greater<ll>());
sort(Rdiff.begin(),Rdiff.end(),greater<ll>());
for(ll i = 0;i < min(Ldiff.size(),Rdiff.size());i++){
total -= min(Ldiff[i],Rdiff[i]);
}
ans = min(ans,total);
for(ll i = 0;i < N;i++){
arr[i] = A[i]; //reset
}
}
cout<<ans<<'\n';
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:30:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'const long unsigned int' [-Wsign-compare]
30 | for(ll i = 0;i < min(Ldiff.size(),Rdiff.size());i++){
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |