Skip to content

Commit 4379680

Browse files
authored
Merge pull request #1635 from AlgorithmWithGod/zinnnn37
[20251210] BOJ / P5 / Two Machines / 김민진
2 parents b52c78b + d3fa6ac commit 4379680

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
```java
2+
import java.io.*;
3+
import java.util.Arrays;
4+
import java.util.StringTokenizer;
5+
6+
public class BJ_17628_Two_Machines {
7+
8+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
10+
private static StringTokenizer st;
11+
12+
private static int N, totalA, ans;
13+
private static int[][] works, dp;
14+
15+
public static void main(String[] args) throws IOException {
16+
init();
17+
sol();
18+
}
19+
20+
private static void init() throws IOException {
21+
N = Integer.parseInt(br.readLine());
22+
totalA = 0;
23+
ans = Integer.MAX_VALUE;
24+
25+
works = new int[N + 1][2];
26+
for (int i = 1; i <= N; i++) {
27+
st = new StringTokenizer(br.readLine());
28+
29+
works[i][0] = Integer.parseInt(st.nextToken());
30+
works[i][1] = Integer.parseInt(st.nextToken());
31+
32+
totalA += works[i][0];
33+
}
34+
// A의 시간을 j로 만들 때, B의 최소 시간
35+
dp = new int[N + 1][totalA + 1];
36+
for (int[] row : dp) {
37+
Arrays.fill(row, Integer.MAX_VALUE);
38+
}
39+
dp[0][0] = 0;
40+
}
41+
42+
private static void sol() throws IOException {
43+
for (int i = 1; i <= N; i++) {
44+
for (int j = 0; j <= totalA; j++) {
45+
if (dp[i - 1][j] == Integer.MAX_VALUE) {
46+
continue;
47+
}
48+
dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + works[i][1]);
49+
50+
if (j + works[i][0] <= totalA) {
51+
dp[i][j + works[i][0]] = Math.min(dp[i][j + works[i][0]], dp[i - 1][j]);
52+
}
53+
}
54+
}
55+
56+
for (int j = 0; j <= totalA; j++) {
57+
if (dp[N][j] == Integer.MAX_VALUE) {
58+
continue;
59+
}
60+
ans = Math.min(ans, Math.max(j, dp[N][j]));
61+
}
62+
bw.write(ans + "");
63+
bw.flush();
64+
bw.close();
65+
br.close();
66+
}
67+
68+
}
69+
```

0 commit comments

Comments
 (0)