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 ll long long
using namespace std;
const int maxn = 2e5 + 7;
int n , a[maxn] ;
ll precnt[maxn] , sufcnt[maxn];
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++)
{
precnt[i] = precnt[i-1];
if(a[i] <= a[i-1])
{
precnt[i] += a[i-1] - a[i] + 1;
}
}
for(int i = n; i >= 1; i--)
{
sufcnt[i] = sufcnt[i+1];
if(a[i] <= a[i+1])
{
sufcnt[i] += a[i+1] - a[i] + 1;
}
}
ll ans = 1e18;
for(int i = 1; i <= n; i++)
{
ans = min(ans , max(precnt[i] , sufcnt[i]));
}
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |