File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8+ int N = Integer .parseInt (br .readLine ());
9+ int [] hp = new int [N + 1 ];
10+ int [] happy = new int [N + 1 ];
11+ int [][] d = new int [N + 1 ][101 ];
12+ StringTokenizer st1 = new StringTokenizer (br .readLine ());
13+ StringTokenizer st2 = new StringTokenizer (br .readLine ());
14+ for (int i = 1 ; i <= N ; i ++) {
15+ hp [i ] = Integer .parseInt (st1 .nextToken ());
16+ happy [i ] = Integer .parseInt (st2 .nextToken ());
17+ }
18+ for (int i = 1 ; i <= N ; i ++) {
19+ for (int j = 1 ; j <= 100 ; j ++) {
20+ if (j - hp [i ] > 0 ) {
21+ d [i ][j ] = Math .max (d [i - 1 ][j ], d [i - 1 ][j - hp [i ]] + happy [i ]);
22+ } else {
23+ d [i ][j ] = d [i - 1 ][j ];
24+ }
25+ }
26+ }
27+ System .out .println (d [N ][100 ]);
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments