File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ public class Main {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+ static StringTokenizer st;
9+ static int N ;
10+ static int [] time;
11+ static int [] reward;
12+ static int [] dp;
13+
14+ public static void main (String [] args ) throws Exception {
15+ N = Integer . parseInt(br. readLine());
16+ time = new int [N + 1 ];
17+ reward = new int [N + 1 ];
18+ dp = new int [N + 2 ];
19+
20+ for (int i = 1 ; i <= N ; i++ ) {
21+ st = new StringTokenizer (br. readLine());
22+ int t = Integer . parseInt(st. nextToken());
23+ int r = Integer . parseInt(st. nextToken());
24+ time[i] = t;
25+ reward[i] = r;
26+ }
27+
28+ int ans = 0 ;
29+ for (int i = 1 ; i <= N ; i++ ) {
30+ dp[i] = Math . max(dp[i],dp[i- 1 ]);
31+ int cur = i+ time[i];
32+ if (cur<= N + 1 ){
33+ dp[cur] = Math . max(dp[cur],dp[i] + reward[i]);
34+ }
35+
36+ }
37+ for (int i = 1 ; i <= N + 1 ; i++ ) {
38+ ans = Math . max(ans,dp[i]);
39+ }
40+ bw. write(ans+ " " );
41+ bw. close();
42+ }
43+ }
44+ ```
You can’t perform that action at this time.
0 commit comments