From 7d87bae4d631f12c0063970ea3557da37f039890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Sun, 25 Jan 2026 21:49:44 +0900 Subject: [PATCH] =?UTF-8?q?[20260125]=20BOJ=20/=20G4=20/=20=ED=98=B8?= =?UTF-8?q?=ED=85=94=20/=20=EA=B0=95=EC=8B=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "25 BOJ \355\230\270\355\205\224.md" | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "25 BOJ \355\230\270\355\205\224.md" diff --git "a/25 BOJ \355\230\270\355\205\224.md" "b/25 BOJ \355\230\270\355\205\224.md" new file mode 100644 index 00000000..59b6657d --- /dev/null +++ "b/25 BOJ \355\230\270\355\205\224.md" @@ -0,0 +1,43 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int c, n; + static int[] dp; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + c = Integer.parseInt(st.nextToken()); + n = Integer.parseInt(st.nextToken()); + + int max = c + 100; + dp = new int[max + 1]; + + Arrays.fill(dp, Integer.MAX_VALUE); + dp[0] = 0; + + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + int cost = Integer.parseInt(st.nextToken()); + int gain = Integer.parseInt(st.nextToken()); + + for (int j = gain; j <= max; j++) { + if (dp[j - gain] == Integer.MAX_VALUE) { + continue; + } + dp[j] = Math.min(dp[j], dp[j - gain] + cost); + } + } + + int ans = Integer.MAX_VALUE; + for (int i = c; i <= max; i++) { + ans = Math.min(ans, dp[i]); + } + + System.out.println(ans); + } +} +```