-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11054_2.cpp
More file actions
43 lines (39 loc) · 912 Bytes
/
11054_2.cpp
File metadata and controls
43 lines (39 loc) · 912 Bytes
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
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int arr[1001];
int increaseDP[1001];
int decreaseDP[1001];
int main(){
int n;
cin>>n;
for(int i=1; i<=n; i++){
cin>>arr[i];
increaseDP[i]=1;
decreaseDP[i]=1;
}
for(int i=1; i<=n; i++){
for(int j=1; j<i; j++){
if(arr[i]>arr[j]){
increaseDP[i]=max(increaseDP[i], increaseDP[j]+1);
}
}
}
for(int i=n; i>=1; i--){
for(int j=n; j>i; j--){
if(arr[i]>arr[j]){
decreaseDP[i]=max(decreaseDP[i], decreaseDP[j]+1);
}
}
}
int result=0;
for(int i=1; i<=n; i++){
result=max(result, increaseDP[i]+decreaseDP[i]-1);
}
// for(int i=1; i<=n; i++){
// cout<<increaseDP[i]<<" "<<decreaseDP[i]<<endl;
// }
cout<<result<<endl;
return 0;
}