-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
36 lines (28 loc) · 998 Bytes
/
Main.java
File metadata and controls
36 lines (28 loc) · 998 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st;
int[] period = new int[n];
int[] cost = new int[n];
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
period[i] = t;
cost[i] = p;
}
int [] dp = new int[n+2];
for (int i = 0; i < n; i++) {
if(period[i]+i<=n+1){
dp[period[i]+i]=Math.max(dp[period[i]+i], dp[i]+cost[i]);
}
dp[i+1]=Math.max(dp[i],dp[i+1]);
}
System.out.println(dp[n]);
}
}