Submission #828892

#TimeUsernameProblemLanguageResultExecution timeMemory
828892raphaelpGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms296 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    long long tot = 0;
    int a = 1, b = N - 2, adda = 0, addb = 0;
    while (a < b)
    {
        while (A[a - 1] - adda < A[a])
        {
            a++;
            adda = 0;
        }
        while (A[b + 1] - addb < A[b])
        {
            b--;
            addb = 0;
        }
        int m = min(A[a - 1] - A[a] + 1 - adda, A[b + 1] - A[b] + 1 - addb);
        adda += m;
        addb += m;
        tot += m;
    }
    if (A[a] == A[b] && a != b)
        tot++;
    cout << tot - 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...