From 76d36d437fd9ff7368fd531454815a5b23daf324 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Mon, 4 Aug 2025 19:58:21 +0900 Subject: [PATCH] =?UTF-8?q?[20250804]=20BOJ=20/=20G5=20/=20=EC=88=98?= =?UTF-8?q?=EA=B0=95=20=EA=B3=BC=EB=AA=A9=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\352\260\225 \352\263\274\353\252\251.md" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "lkhyun/202508/04 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" diff --git "a/lkhyun/202508/04 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" "b/lkhyun/202508/04 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" new file mode 100644 index 00000000..bc5b86ee --- /dev/null +++ "b/lkhyun/202508/04 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" @@ -0,0 +1,39 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,K; + static int[] prior; + static int[] studyTime; + static int[] dp; + + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + prior = new int[K]; + studyTime = new int[K]; + dp = new int[N+1]; + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + int I = Integer.parseInt(st.nextToken()); + int T = Integer.parseInt(st.nextToken()); + prior[i] = I; + studyTime[i] = T; + } + + for (int i = 0; i < K; i++) { + for (int j = N; j >= studyTime[i]; j--) { + dp[j] = Math.max(dp[j],dp[j-studyTime[i]]+prior[i]); + } + } + bw.write(dp[N]+""); + bw.close(); + } +} +```