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;
#define int long long
#define pii pair<long long, long long>
#define t3i tuple<long long, long long, long long>
signed main() {
ios_base::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> d(n - 1);
for (int i = 0; i < n - 1; i++) d[i] = a[i + 1] - a[i];
vector<int> pos(n), neg(n);
for (int i = 0; i < n - 1; i++) pos[i + 1] = pos[i] + max(0ll, 1 - d[i]);
for (int i = n - 2; i >= 0; i--) neg[i] = neg[i + 1] + max(0ll, d[i] + 1);
/*for (int i = 0; i < n - 1; i++) cout << d[i] << "\t";
cout << "\n";
for (int i = 0; i < n; i++) cout << pos[i] << "\t";
cout << "\n";
for (int i = 0; i < n; i++) cout << neg[i] << "\t";
cout << "\n";*/
int ans = 1e11;
for (int i = 0; i < n - 1; i++) ans = min(ans, max(pos[i], neg[i]));
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |