-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaekjoon7579.java
More file actions
42 lines (39 loc) · 890 Bytes
/
Baekjoon7579.java
File metadata and controls
42 lines (39 loc) · 890 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
37
38
39
40
41
42
package Main;
import java.util.*;
public class Baekjoon7579 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int memory[] = new int[N+1];
int cost[] = new int[N+1];
int dp[][] = new int[N+1][10001];
for(int i=1;i<=N;i++)
memory[i] = sc.nextInt();
for(int i=1;i<=N;i++)
cost[i] = sc.nextInt();
for(int i=0;i<=N;i++)
Arrays.fill(dp[i], -1);
dp[0][0] = 0;
for(int i=1;i<=N;i++) {
for(int j=0;j<=10000;j++) {
if(dp[i-1][j]>=0) {
int a = j;
int mem = 0;
for(int k=0; k<2; k++) {
dp[i][a] = Math.max(dp[i][a], dp[i-1][j] + mem);
mem = memory[i];
a = j+cost[i];
}
}
}
}
for(int i=0;i<=10000;i++) {
if(dp[N][i] >= M) {
System.out.println(i);
break;
}
}
sc.close();
}
}