Skip to content

Commit 982846b

Browse files
authored
Merge pull request #112 from AlgorithmWithGod/Seol-JY
[20250213] BOJ / 골드4 / 오렌지 출하 / 설진영
2 parents 2200205 + 86ea1ca commit 982846b

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.StringTokenizer;
4+
public class Main {
5+
public static void main(String[] args) throws IOException {
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
StringTokenizer st = new StringTokenizer(br.readLine());
8+
9+
final int N = Integer.parseInt(st.nextToken());
10+
final int M =Integer.parseInt(st.nextToken());
11+
final int K = Integer.parseInt(st.nextToken());
12+
13+
int[] arr = new int[N];
14+
long[] dp = new long[N+1];
15+
for (int i = 0; i < N; i++) {
16+
arr[i] = Integer.parseInt(br.readLine());
17+
}
18+
19+
dp[1] = K;
20+
for (int index = 1; index < N; index++) {
21+
long min = Long.MAX_VALUE;
22+
long max = Long.MIN_VALUE;
23+
24+
long finalMin = Long.MAX_VALUE;
25+
for (int i = 0; i < M; i++) {
26+
if(index - i - 1 < -1) break;
27+
min = Math.min(min, arr[index - i]);
28+
max = Math.max(max, arr[index - i]);
29+
finalMin = Math.min(finalMin, dp[index - i] + K + (i + 1) * (max - min));
30+
}
31+
32+
dp[index+1] = finalMin;
33+
}
34+
System.out.println(dp[N]);
35+
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)