Skip to content

Commit 5bffbb0

Browse files
authored
Create BJ_7579_앱.java
1 parent 9510b20 commit 5bffbb0

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

250414/BJ_7579_앱.java

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class Main {
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st = new StringTokenizer(br.readLine());
10+
11+
int N = Integer.parseInt(st.nextToken());
12+
int M = Integer.parseInt(st.nextToken());
13+
14+
int[] memory = new int[N + 1];
15+
int[] cost = new int[N + 1];
16+
17+
// 차지하는 메모리 저장
18+
st = new StringTokenizer(br.readLine());
19+
for (int i = 1; i <= N; i++) {
20+
memory[i] = Integer.parseInt(st.nextToken());
21+
}
22+
23+
int costSum = 0;
24+
25+
// 비용 저장
26+
st = new StringTokenizer(br.readLine());
27+
for (int i = 1; i <= N; i++) {
28+
cost[i] = Integer.parseInt(st.nextToken());
29+
costSum += cost[i];
30+
}
31+
32+
int[][] dp = new int[N + 1][costSum + 1];
33+
34+
int answer = Integer.MAX_VALUE;
35+
36+
for (int i = 0; i <= N; i++) {
37+
for (int j = 0; j <= costSum; j++) {
38+
if (i == 0) {
39+
if (j >= cost[i]) dp[i][j] = memory[i];
40+
} else {
41+
if (j >= cost[i]) dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - cost[i]] + memory[i]);
42+
else dp[i][j] = dp[i - 1][j];
43+
}
44+
45+
if (dp[i][j] >= M) answer = Math.min(answer, j);
46+
}
47+
48+
49+
}
50+
51+
System.out.println(answer);
52+
}
53+
}

0 commit comments

Comments
 (0)