From 21f2f10f76bc48924e93929e09ca86f00f52dc47 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Tue, 26 Aug 2025 21:36:01 +0900 Subject: [PATCH] =?UTF-8?q?[20250826]=20BOJ=20/=20G5=20/=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC2=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202508/26 BOJ \355\207\264\354\202\2542" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "0224LJH/202508/26 BOJ \355\207\264\354\202\2542" diff --git "a/0224LJH/202508/26 BOJ \355\207\264\354\202\2542" "b/0224LJH/202508/26 BOJ \355\207\264\354\202\2542" new file mode 100644 index 00000000..b504201d --- /dev/null +++ "b/0224LJH/202508/26 BOJ \355\207\264\354\202\2542" @@ -0,0 +1,54 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int cnt,ans; + static int[] cost; + static int[] money; + static int[] dp; + + public static void main(String[] args) throws Exception { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + cnt = Integer.parseInt(br.readLine()); + cost = new int[cnt+1]; + money = new int[cnt+1]; + dp = new int[cnt+51]; + ans = 0; + for (int i = 1; i <= cnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + cost[i] = Integer.parseInt(st.nextToken()); + money[i] = Integer.parseInt(st.nextToken()); + } + } + + public static void process(){ + for (int i = 1; i <= cnt; i++) { + dp[i] = Math.max(dp[i],dp[i-1]); + if (i + cost[i]-1 > cnt) { + continue; + } + + dp[i + cost[i]-1] = Math.max (dp[i+cost[i]-1] , dp[i-1] + money[i]); + } + + for (int i = 1; i<= cnt; i++) { + System.out.println(dp[i]); + ans = Math.max(ans, dp[i]); + } + } + + public static void print(){ + System.out.println(ans); + } + +``` +}