-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ14501.java
31 lines (26 loc) · 892 Bytes
/
BOJ14501.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package DP;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BOJ14501 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int day = Integer.parseInt(br.readLine());
int[] run_day = new int[20];
int[] pay = new int[20];
int[] dp = new int[20];
for(int i=1; i<=day; i++){
String[] input = br.readLine().split(" ");
run_day[i] = Integer.parseInt(input[0]);
pay[i] = Integer.parseInt(input[1]);
}
for(int i = day; i>0; i--){
if(run_day[i]>day-i+1){
dp[i] = dp[i+1];
}else {
dp[i] = Math.max(pay[i]+dp[i+run_day[i]],dp[i+1]);
}
}
System.out.print(dp[1]);
}
}