# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
372619 | blue | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++11 | 0 ms | 0 KiB |
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>
using namespace std;
int main()
{
int N;
cin >> N;
long long A[N+1];
for(int i = 1; i <= N; i++) cin >> A[i];
long long res = 4'000'000'000'000'000'000;
long long inc[N+1], dec[N+1];
inc[1] = 0;
dec[N] = 0;
for(int i = 2; i <= N; i++) inc[i] = inc[i-1] + max((A[i-1] + 1) - A[i], 0LL);
for(int i = N-1; i >= 1; i--) dec[i] = dec[i+1] + max((A[i+1] + 1) - A[i], 0LL);
for(int i = 1; i <= N; i++) res = min(res, max(inc[i], dec[i]));
cout << res << '\n';
}