# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
371264 | arnold518 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 38 ms | 5100 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
const ll INF = 1e18;
int N;
ll A[MAXN+10];
ll ans=INF;
ll B[MAXN+10], C[MAXN+10];
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
for(int i=2; i<=N; i++)
{
B[i]=B[i-1]+max(0ll, A[i-1]+1-A[i]);
}
for(int i=N-1; i>=1; i--)
{
C[i]=C[i+1]+max(0ll, A[i+1]+1-A[i]);
}
ll ans=INF;
for(int i=1; i<N; i++)
{
ll t=max(B[i], C[i+1]);
if(A[i]+B[i]==A[i+1]+C[i+1]) t++;
ans=min(ans, t);
}
ans=min(ans, B[N]);
ans=min(ans, C[1]);
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |