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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
#include <array>
#include <functional>
#include <stack>
#include <memory>
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#define int long long
#define app push_back
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl; }(#__VA_ARGS__, ":", __VA_ARGS__)
#define debugv(v) do { cout << #v << ": "; for (auto x : v) cout << x << ' '; cout << endl; } while(0)
#else
#define debug(...)
#define debugv(v)
#endif
int32_t main() {
cin.tie(0);ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector <int> a(n), d(n - 1), pre(n), suf(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i + 1 < n; ++i) {
d[i] = a[i + 1] - a[i];
pre[i + 1] = pre[i];
if (d[i] <= 0) {
pre[i + 1] += 1 - d[i];
}
}
for (int i = n - 1; i > 0; --i) {
suf[i - 1] = suf[i];
if (d[i - 1] >= 0) {
suf[i - 1] += d[i - 1] + 1;
}
}
int ans = 1e18;
for (int i = 0; i < n; ++i) {
ans = min(ans, max(pre[i] , suf[i]));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |