제출 #646906

#제출 시각아이디문제언어결과실행 시간메모리
646906OlsonGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms212 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...