-
Notifications
You must be signed in to change notification settings - Fork 53
/
66B - Petya and Countryside.cpp
64 lines (54 loc) · 997 Bytes
/
66B - Petya and Countryside.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//problem name: 66B - Petya and Countryside
//status:accepted
//problem link:http://codeforces.com/contest/66/problem/B
//author:mohand sakr
#include <iostream>
using namespace std;
int arr[1005];
int solve(int n,int index){
int right=0;
int left=0;
int rigthreference=arr[index];
int leftreference=arr[index];
for(int i=index;i<n;i++){
if(arr[i]>rigthreference){
break;
}
else{
++right;
if(arr[i]<rigthreference){
rigthreference=arr[i];
}
}
}
for(int i=index-1;i>=0;i--){
if(arr[i]>leftreference){
break;
}
else{
++left;
if(arr[i]<leftreference){
leftreference=arr[i];
}
}
}
return right+left;
}
int main() {
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
int resultvalue=0;
int resultindex=0;
for(int i=0;i<n;i++){
int value=solve(n,i);
if(value>resultvalue){
resultindex=i;
resultvalue=value;
}
}
cout<<resultvalue<<endl;
return 0;
}