From 50b2b6fc2bb883aed1ef42211c7b0bbdc48dd0ab Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sat, 27 Dec 2025 23:27:25 +0900 Subject: [PATCH] =?UTF-8?q?[20251227]=20BOJ=20/=20G4=20/=20=EC=98=A4?= =?UTF-8?q?=EB=A0=8C=EC=A7=80=20=EC=B6=9C=ED=95=98=20/=20=ED=95=9C?= =?UTF-8?q?=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\247\200 \354\266\234\355\225\230.md" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "Ukj0ng/202512/27 BOJ G4 \354\230\244\353\240\214\354\247\200 \354\266\234\355\225\230.md" diff --git "a/Ukj0ng/202512/27 BOJ G4 \354\230\244\353\240\214\354\247\200 \354\266\234\355\225\230.md" "b/Ukj0ng/202512/27 BOJ G4 \354\230\244\353\240\214\354\247\200 \354\266\234\355\225\230.md" new file mode 100644 index 00000000..2f65b97e --- /dev/null +++ "b/Ukj0ng/202512/27 BOJ G4 \354\230\244\353\240\214\354\247\200 \354\266\234\355\225\230.md" @@ -0,0 +1,51 @@ +``` +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final long INF = (long)2e14; + private static long[] dp; + private static int[] oranges; + private static int N, M, K; + + public static void main(String[] args) throws IOException { + init(); + + bw.write(dp[N] + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + oranges = new int[N+1]; + dp = new long[N+1]; + for (int i = 1; i <= N; i++) { + oranges[i] = Integer.parseInt(br.readLine()); + } + + Arrays.fill(dp, INF); + dp[0] = 0; + + for (int i = 1; i <= N; i++) { + long max = Long.MIN_VALUE; + long min = Long.MAX_VALUE; + + for (int j = i; j >= Math.max(1, i-M+1); j--) { + max = Math.max(max, oranges[j]); + min = Math.min(min, oranges[j]); + long cost = K+(i-j+1)*(max-min); + dp[i] = Math.min(dp[i], dp[j-1]+cost); + } + } + } +} +```