Skip to content

Commit f113b6b

Browse files
authored
[20250705] BOJ / G4 / 호텔 / 설진영
1 parent 1ba9ec4 commit f113b6b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Seol-JY/202507/05 BOJ G4 호텔.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
10+
int C = Integer.parseInt(st.nextToken());
11+
int N = Integer.parseInt(st.nextToken());
12+
13+
int[] cost = new int[N];
14+
int[] customer = new int[N];
15+
16+
for (int i = 0; i < N; i++) {
17+
st = new StringTokenizer(br.readLine());
18+
cost[i] = Integer.parseInt(st.nextToken());
19+
customer[i] = Integer.parseInt(st.nextToken());
20+
}
21+
22+
int[] dp = new int[C + 101];
23+
Arrays.fill(dp, Integer.MAX_VALUE);
24+
dp[0] = 0;
25+
26+
for (int i = 0; i < N; i++) {
27+
for (int j = customer[i]; j < dp.length; j++) {
28+
if (dp[j - customer[i]] != Integer.MAX_VALUE) {
29+
dp[j] = Math.min(dp[j], dp[j - customer[i]] + cost[i]);
30+
}
31+
}
32+
}
33+
34+
int result = Integer.MAX_VALUE;
35+
for (int i = C; i < dp.length; i++) {
36+
result = Math.min(result, dp[i]);
37+
}
38+
39+
System.out.println(result);
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)