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