This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |