-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path241116-11054.java
41 lines (39 loc) · 1.32 KB
/
241116-11054.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int[] positive = new int[N];
int[] negative = new int[N];
for (int i = 0; i < N; i++) {
positive[i] = 1;
for (int j = 0; j < i; j++) {
if (arr[j] < arr[i]) {
positive[i] = Math.max(positive[j] + 1, positive[i]);
}
}
}
for (int i = N - 1; i >= 0; i--) {
negative[i] = 1;
for (int j = N - 1; j > i; j--) {
if (arr[j] < arr[i]) {
negative[i] = Math.max(negative[j] + 1, negative[i]);
}
}
}
int max = 0;
for (int i = 0; i < N; i++) {
max = Math.max(max, positive[i] + negative[i]);
}
System.out.print(max - 1);
}
}