From 4d00975a04f33933f28626438798d21ed56fa832 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Sun, 28 Sep 2025 18:19:12 +0900 Subject: [PATCH] =?UTF-8?q?[20250928]=20BOJ=20/=20G5=20/=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC=202=20/=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../28 BOJ G5 \355\207\264\354\202\254 2.md" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "zinnnn37/202509/28 BOJ G5 \355\207\264\354\202\254 2.md" diff --git "a/zinnnn37/202509/28 BOJ G5 \355\207\264\354\202\254 2.md" "b/zinnnn37/202509/28 BOJ G5 \355\207\264\354\202\254 2.md" new file mode 100644 index 00000000..c49ec82a --- /dev/null +++ "b/zinnnn37/202509/28 BOJ G5 \355\207\264\354\202\254 2.md" @@ -0,0 +1,59 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class BJ_15486_퇴사_2 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static StringTokenizer st; + + private static int N; + private static int[] dp; + private static Schedule[] schedule; + + private static class Schedule { + int time; + int pay; + + Schedule(int time, int pay) { + this.time = time; + this.pay = pay; + } + } + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + dp = new int[N + 1]; + schedule = new Schedule[N + 1]; + + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + int t = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + + schedule[i] = new Schedule(t, p); + } + } + + private static void sol() throws IOException { + for (int i = 1; i <= N; i++) { + dp[i] = Math.max(dp[i], dp[i - 1]); + + int idx = schedule[i].time + i - 1; + if (idx > N) continue; + + dp[idx] = Math.max(dp[i - 1] + schedule[i].pay, dp[idx]); + } + + System.out.println(dp[N]); + br.close(); + } +} +``` \ No newline at end of file