From f113b6b23cf60fb6879b0ccecbae30f56a860d8f Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sat, 5 Jul 2025 22:03:19 +0900 Subject: [PATCH] =?UTF-8?q?[20250705]=20BOJ=20/=20G4=20/=20=ED=98=B8?= =?UTF-8?q?=ED=85=94=20/=20=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../05 BOJ G4 \355\230\270\355\205\224.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "Seol-JY/202507/05 BOJ G4 \355\230\270\355\205\224.md" diff --git "a/Seol-JY/202507/05 BOJ G4 \355\230\270\355\205\224.md" "b/Seol-JY/202507/05 BOJ G4 \355\230\270\355\205\224.md" new file mode 100644 index 00000000..3f6814bc --- /dev/null +++ "b/Seol-JY/202507/05 BOJ G4 \355\230\270\355\205\224.md" @@ -0,0 +1,42 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int C = Integer.parseInt(st.nextToken()); + int N = Integer.parseInt(st.nextToken()); + + int[] cost = new int[N]; + int[] customer = new int[N]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + cost[i] = Integer.parseInt(st.nextToken()); + customer[i] = Integer.parseInt(st.nextToken()); + } + + int[] dp = new int[C + 101]; + Arrays.fill(dp, Integer.MAX_VALUE); + dp[0] = 0; + + for (int i = 0; i < N; i++) { + for (int j = customer[i]; j < dp.length; j++) { + if (dp[j - customer[i]] != Integer.MAX_VALUE) { + dp[j] = Math.min(dp[j], dp[j - customer[i]] + cost[i]); + } + } + } + + int result = Integer.MAX_VALUE; + for (int i = C; i < dp.length; i++) { + result = Math.min(result, dp[i]); + } + + System.out.println(result); + } +} +```