-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11054.cpp
46 lines (42 loc) · 901 Bytes
/
11054.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
#include <iostream>
#include <vector>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std ;
int arr[1001] ;
int upper[1001] ;
int lower[1001] ;
void find_increase(int N)
{
for(int i = 1 ; i<= N ; i++)
{
for(int j = 1 ; j <= i ; j++)
if(arr[i] > arr[j]) upper[i] = max(upper[i], upper[j]) ;
upper[i]++ ;
}
}
void find_decrease(int N)
{
for(int i = N ; i > 0 ; i--)
{
for(int j = N ; j >= i ; j--)
if(arr[i] > arr[j]) lower[i] = max(lower[i], lower[j]) ;
lower[i]++ ;
}
}
int main()
{
SETTING ;
int N, answer = 0 ;
cin >> N ;
for(int i = 1 ; i<= N ; i++)
{
cin >> arr[i] ;
}
find_increase(N) ;
find_decrease(N) ;
for(int i = 1 ; i <= N ; i++)
{
answer = max(answer, upper[i] + lower[i] - 1) ;
}
cout << answer << "\n" ;
}