-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaekJoon14501.java
More file actions
45 lines (37 loc) · 1006 Bytes
/
BaekJoon14501.java
File metadata and controls
45 lines (37 loc) · 1006 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BaekJoon14501 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
int[] t = new int[n + 1];
int[] p = new int[n + 1];
int[] d = new int[n + 2];
for (int i = 1; i < n + 1; i++) {
st = new StringTokenizer(br.readLine());
t[i] = Integer.parseInt(st.nextToken());
p[i] = Integer.parseInt(st.nextToken());
}
for (int i = d.length - 2; i > 0; i--) {
if (i + t[i] > n + 1)
d[i] = d[i + 1];
else {
d[i] = Math.max(d[i+1], d[i + t[i]] + p[i]);
}
}
System.out.println(d[1]);
}
}
/*
7
3 10
5 20
1 10
1 20
2 15
4 40
2 200
*/