Submission #646906

# Submission time Handle Problem Language Result Execution time Memory
646906 2022-10-01T00:35:23 Z Olson Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
0 / 100
0 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;cin>>n;
    ll m=-1,p=-1;
    ll a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]>m){
            m=a[i];
            p=i;
        }
    }
    int l=p, r=p;
    ll ans=0;
    while(true){
        while(l>0&&a[l]>a[l-1]) l--;
        while(r<n-1&&a[r]>a[r+1]) r++;
        if(l==0&&r==n-1)break;
        else if(l==0){
            ans+=a[r+1]-a[r]+1;
            r++;
        }
        else if(r==n-1){
            ans+=a[l-1]-a[l]+1;
            l--;
        }
        else{
            ll d1=a[r+1]-a[r]+1;
            ll d2=a[l-1]-a[l]+1;
            ans+=max(d1,d2);
            r++;l--;
        }
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -