|
| 1 | +```java |
| 2 | +import java.io.BufferedReader; |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.InputStreamReader; |
| 5 | +import java.util.StringTokenizer; |
| 6 | + |
| 7 | +public class BJ_15486_퇴사_2 { |
| 8 | + |
| 9 | + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + private static StringTokenizer st; |
| 11 | + |
| 12 | + private static int N; |
| 13 | + private static int[] dp; |
| 14 | + private static Schedule[] schedule; |
| 15 | + |
| 16 | + private static class Schedule { |
| 17 | + int time; |
| 18 | + int pay; |
| 19 | + |
| 20 | + Schedule(int time, int pay) { |
| 21 | + this.time = time; |
| 22 | + this.pay = pay; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + public static void main(String[] args) throws IOException { |
| 27 | + init(); |
| 28 | + sol(); |
| 29 | + } |
| 30 | + |
| 31 | + private static void init() throws IOException { |
| 32 | + N = Integer.parseInt(br.readLine()); |
| 33 | + dp = new int[N + 1]; |
| 34 | + schedule = new Schedule[N + 1]; |
| 35 | + |
| 36 | + for (int i = 1; i <= N; i++) { |
| 37 | + st = new StringTokenizer(br.readLine()); |
| 38 | + int t = Integer.parseInt(st.nextToken()); |
| 39 | + int p = Integer.parseInt(st.nextToken()); |
| 40 | + |
| 41 | + schedule[i] = new Schedule(t, p); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + private static void sol() throws IOException { |
| 46 | + for (int i = 1; i <= N; i++) { |
| 47 | + dp[i] = Math.max(dp[i], dp[i - 1]); |
| 48 | + |
| 49 | + int idx = schedule[i].time + i - 1; |
| 50 | + if (idx > N) continue; |
| 51 | + |
| 52 | + dp[idx] = Math.max(dp[i - 1] + schedule[i].pay, dp[idx]); |
| 53 | + } |
| 54 | + |
| 55 | + System.out.println(dp[N]); |
| 56 | + br.close(); |
| 57 | + } |
| 58 | +} |
| 59 | +``` |
0 commit comments