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;
const int N = 1e5 + 5;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// #endif
long long n, cevap = 1e16;
cin >> n;
vector<long long> vec(n + 2), prefix(n + 1), suffix(n + 1);
for(int i = 1; i <= n; i++)
cin >> vec[i];
for(int i = 2; i <= n; i++)
{
prefix[i] = prefix[i - 1];
prefix[i] += max(0LL, (vec[i - 1] + 1) - vec[i]);
}
for(int i = n - 1; i > 0; i--)
{
suffix[i] = suffix[i + 1];
suffix[i] += max(0LL, (vec[i + 1] + 1) - vec[i]);
}
prefix[1] = suffix[n] = 0;
for(int i = 1; i <= n; i++)
{
cevap = min(cevap, max(prefix[i], suffix[i]));
}
cout << cevap << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |