Skip to content

Commit 81e077e

Browse files
authored
[20260130] BOJ / G3 / 소형기관차 / 한종욱
1 parent c618215 commit 81e077e

File tree

1 file changed

+41
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)