Submission #646903

#TimeUsernameProblemLanguageResultExecution timeMemory
646903OlsonGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n;cin>>n; int m=-1,p=-1; int 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; int ans=0; while(l>=0&&r<n){ 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{ int d1=a[r+1]-a[r]+1; int 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...