forked from jxixeun/jxix_java_algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ13750.java
More file actions
29 lines (27 loc) · 937 Bytes
/
Copy pathBOJ13750.java
File metadata and controls
29 lines (27 loc) · 937 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
package baekjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BOJ13750 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int [] A = new int[N];
int [] low = new int[N];
int [] high = new int[N];
for (int i = 0; i < N; i++) {
A[i] = Integer.parseInt(br.readLine());
low[i] = 1;
high[i] = 1;
}
for (int k = 0; k < N; k++) {
for (int j = 0; j < k; j++) {
if (A[j] > A[k])
low[k] = Math.max(low[k], high[j] + 1);
if (A[j] < A[k])
high[k] = Math.max(high[k], low[j] + 1);
}
}
System.out.println(Math.max(low[N-1], high[N-1]));
}
}