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 <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
typedef long long llong;
const int MAXN = 200000 + 10;
const int INF = 1e9;
int a[MAXN], n;
llong prefix[MAXN];
llong suffix[MAXN];
void solve()
{
prefix[1] = suffix[n] = 0;
for (int i = 2 ; i <= n ; ++i)
{
prefix[i] = prefix[i-1] + std::max(0, a[i-1] - a[i] + 1);
}
for (int i = n-1 ; i >= 1 ; --i)
{
suffix[i] = suffix[i+1] + std::max(0, a[i+1] - a[i] + 1);
}
llong ans = 1LL * INF * INF;
for (int i = 1 ; i <= n ; ++i)
{
ans = std::min(ans, std::max(prefix[i], suffix[i]));
}
std::cout << ans << '\n';
}
void read()
{
std::cin >> n;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |