-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB14501_2.java
More file actions
32 lines (24 loc) · 878 Bytes
/
B14501_2.java
File metadata and controls
32 lines (24 loc) · 878 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
package Practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B14501_2 { //Åð»ç(DP)
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] T = new int[N], P = new int[N], dp = new int[N + 1];
for(int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
T[i] = Integer.parseInt(st.nextToken());
P[i] = Integer.parseInt(st.nextToken());
}
if(T[0] <= N) dp[T[0]] = P[0];
for(int i = 1; i < N; i++) {
dp[i] = Math.max(dp[i], dp[i - 1]);
if(i + T[i] > N) continue;
dp[i + T[i]] = Math.max(dp[i + T[i]], dp[i] + P[i]);
}
System.out.println(Math.max(dp[N], dp[N - 1]));
}
}