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>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
signed main()
{
IO_OP;
int n;
cin >> n;
vi a(n);
for(int i = 0; i < n; i++)
cin >> a[i];
V<ll> p(n), s(n);
for(int i = 1; i < n; i++)
p[i] = p[i - 1] + max(0, a[i - 1] - a[i] + 1);
for(int i = n - 2; i >= 0; i--)
s[i] = s[i + 1] + max(0, a[i + 1] - a[i] + 1);
ll ans = 1e18;
for(int i = 0; i < n; i++) {
ans = min(ans, max(s[i], p[i]));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |