Skip to content

Commit 037d6a5

Browse files
authored
Merge pull request #936 from AlgorithmWithGod/lkhyun
[20250920] BOJ / G4 / 롤러코스터 / 이강현
2 parents 2cda62e + 1ac8abf commit 037d6a5

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int N;
10+
static int[] tops;
11+
static int[] decrease;
12+
static int[] increase;
13+
14+
public static void main(String[] args) throws IOException {
15+
N = Integer.parseInt(br.readLine());
16+
tops = new int[N];
17+
decrease = new int[N];
18+
increase = new int[N];
19+
20+
st = new StringTokenizer(br.readLine());
21+
for (int i = 0; i < N; i++) {
22+
tops[i] = Integer.parseInt(st.nextToken());
23+
}
24+
25+
for (int i = 0; i < N; i++) {
26+
decrease[i] = 1;
27+
for (int j = 0; j < i; j++) {
28+
if (tops[j] > tops[i] && decrease[i] < decrease[j] + 1) {
29+
decrease[i] = decrease[j] + 1;
30+
}
31+
}
32+
}
33+
34+
for (int i = N - 1; i >= 0; i--) {
35+
increase[i] = 1;
36+
for (int j = i + 1; j < N; j++) {
37+
if (tops[i] < tops[j] && increase[i] < increase[j] + 1) {
38+
increase[i] = increase[j] + 1;
39+
}
40+
}
41+
}
42+
43+
int maxLen = 0;
44+
for (int i = 0; i < N; i++) {
45+
maxLen = Math.max(maxLen, decrease[i] + increase[i] - 1);
46+
}
47+
48+
bw.write(maxLen + "");
49+
bw.close();
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)