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 <iomanip>
using namespace std;
#define INF 1000000000000000LL
long long n, i, a[200100], prefval[200100], sufval[200100], ans;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (i = 1; i <= n; i++)
{
cin >> a[i];
}
prefval[1] = 0;
for (i = 2; i <= n; i++)
{
prefval[i] = prefval[i-1];
if (a[i] <= a[i-1])
{
prefval[i] += (a[i-1] - a[i] + 1);
}
}
sufval[n] = 0;
for (i = n-1; i >= 1; i--)
{
sufval[i] = sufval[i+1];
if (a[i] <= a[i+1])
{
sufval[i] += (a[i+1] - a[i] + 1);;
}
}
ans = max(prefval[1], sufval[1]);
for (i = 2; i <= n; i++)
{
ans = min(ans, max(prefval[i], sufval[i]));
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |