From aecd775a6bde8e91a11599107429dd94e78fc444 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 21 Jul 2025 17:33:48 +0900 Subject: [PATCH] =?UTF-8?q?[20250721]=20BOJ=20/=20G5=20/=20=EB=B2=BC?= =?UTF-8?q?=EB=9D=BD=EC=B9=98=EA=B8=B0=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\235\275\354\271\230\352\270\260.md" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "suyeun84/202507/21 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" diff --git "a/suyeun84/202507/21 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" "b/suyeun84/202507/21 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" new file mode 100644 index 00000000..5c4057b0 --- /dev/null +++ "b/suyeun84/202507/21 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" @@ -0,0 +1,37 @@ +```java +import java.util.*; +import java.io.*; + +public class boj29704 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static int n; + static int t; + static int[] dp; + + public static void main(String[] args) throws Exception { + nextLine(); + n = nextInt(); + t = nextInt(); + dp = new int[t+1]; + + int all = 0; + while (n-- > 0) { + nextLine(); + int d = nextInt(); + int m = nextInt(); + all += m; + + for (int i = t; i >= 0; i--) { + if (i < d) break; + dp[i] = Math.max(dp[i], dp[i-d] +m); + } + } + + System.out.println(all - dp[t]); + } +} +```