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;
typedef long long ll;
typedef vector<int> vi;
typedef vector <ll> vll;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector <pii> vpii;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define endl "\n"
#define int ll
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> up(n);
vector<int> down(n);
for(int i = 1; i < n; i++) {
up[i] = up[i-1] + max(0ll, (a[i-1] - a[i] + 1));
}
for(int i = n-2; i >= 0; i--) {
down[i] = down[i+1] + max(0ll, (a[i+1] - a[i] + 1));
}
int res = max(up[0], down[0]);
for(int i = 0; i < n; i++) {
res = min(res, max(up[i], down[i]));
}
cout << res << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |