Skip to content

Commit f9cc523

Browse files
authored
[20250915] BOJ / G5 / 조 짜기 / 이준희
1 parent 19a2db3 commit f9cc523

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static List<Deque<Integer>> wheel = new ArrayList<>();
8+
9+
public static void main(String[] args) throws Exception {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringTokenizer st;
12+
13+
int n = Integer.parseInt(br.readLine());
14+
int[] arr = new int[n];
15+
int[] dp = new int[n];
16+
st = new StringTokenizer(br.readLine());
17+
for (int i = 0; i < n; i++) {
18+
arr[i] = Integer.parseInt(st.nextToken());
19+
}
20+
21+
for (int i = 0; i < n; i++) {
22+
int max = arr[i];
23+
int min = arr[i];
24+
for (int j = i; j >= 0; j--) {
25+
max = Math.max(max, arr[j]);
26+
min = Math.min(min, arr[j]);
27+
if (j == 0) {
28+
dp[i] = Math.max(dp[i], max - min);
29+
} else {
30+
dp[i] = Math.max(dp[i], dp[j - 1] + (max - min));
31+
}
32+
}
33+
}
34+
35+
System.out.println(dp[n - 1]);
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)