-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1020.cpp
38 lines (38 loc) · 812 Bytes
/
P1020.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
#include<iostream>
using namespace std;
const int MAXN=100005;
int num[MAXN];
int f[MAXN];
int dp[MAXN];
int main(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
int n=1;
while(cin>>num[n++]);
n--;
for(int i=1;i<=n;i++){
f[i]=1;
dp[i]=1;
}
int max_up=-1;
for(int i=1;i<=n;i++){
for(int j=1;j<=i-1;j++){
if(num[i]>num[j]){
f[i]=max(f[i],f[j]+1);
}
if(f[i]>max_up) max_up=f[i];
}
}
int max_down=-1;
for(int i=1;i<=n;i++){
for(int j=1;j<=i-1;j++){
if(num[i]<=num[j]){
dp[i]=max(dp[i],dp[j]+1);
}
if(dp[i]>max_down) max_down=dp[i];
}
}
cout<<max_down<<endl;
cout<<max_up<<endl;
return 0;
}