#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 |
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 |
- |