-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_11054
More file actions
55 lines (42 loc) · 1.27 KB
/
BAEKJOON_11054
File metadata and controls
55 lines (42 loc) · 1.27 KB
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
import org.w3c.dom.Node;
import java.io.*;
import java.math.BigInteger;
import java.sql.Array;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int[] A = new int[N + 1];
int[] D = new int[N + 1];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=1; i<=N; i++){
A[i] = Integer.parseInt(st.nextToken());
}
for(int i=1; i<=N; i++){
D[i] = 1;
for(int j=1; j<i; j++){
if (A[j] < A[i] && D[i] < D[j] + 1) {
D[i] = D[j]+1;
}
}
}
for(int i=1; i<=N; i++){
for(int j=1; j<i; j++){
if (A[j] > A[i] && D[i] < D[j] + 1) {
D[i] = D[j]+1;
}
}
}
int ans = D[0];
for(int i=1; i<=N; i++){
if (ans < D[i]) {
ans = D[i];
}
}
bw.write(String.valueOf(ans));
bw.flush();
bw.close();
}
}