Submission #883379

#TimeUsernameProblemLanguageResultExecution timeMemory
883379elisaipateGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms348 KiB
#include <iostream>

using namespace std;

#define nmax 200003

int v[nmax];
int main()
{
    int n, i, x, y, rez = 0;
    cin >> n;
    for( i = 0; i < n; i++ )
        cin >> v[i];

    x = 0;
    y = n - 1;
    while( y - x > 0 ) {
        if( v[x] < v[x+1] )
            x++;
        else if( v[y-1] > v[y] )
            y--;
        else {
            if( v[x] - v[x+1] + 1 < v[y] - v[y-1] + 1 ) {
                rez += v[x] - v[x+1] + 1;
                v[y] -= v[x] - v[x+1] + 1;
                x++;
            } else {
                rez += v[y] - v[y-1] + 1;
                v[x] -= v[y] - v[y-1] + 1;
                y--;
            }
        }
        /*cout << rez << " ";
        for( i = 0; i < n; i++ )
            cout << v[i] << " ";
        cout << "\n";*/
    }
    cout << rez;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...