Skip to content

Commit f0bfbf6

Browse files
authored
[20250809] BOJ / G5 / 조 짜기 / 김수연
1 parent 5b11a54 commit f0bfbf6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj2229 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
nextLine();
15+
int[] score = new int[N+1];
16+
int[] dp = new int[N+1];
17+
dp[0] = 0;
18+
int max = 0;
19+
for (int i = 1; i <= N; i++) {
20+
score[i] = nextInt();
21+
for (int j = i-1; j >= 1; j--) {
22+
max = Math.max(max, Math.abs(score[i] - score[j]) + dp[j-1]);
23+
}
24+
dp[i] = max;
25+
}
26+
System.out.println(dp[N]);
27+
}
28+
}
29+
```

0 commit comments

Comments
 (0)