Skip to content

Commit e49eccd

Browse files
authored
Merge pull request #1833 from AlgorithmWithGod/ksinji
[20260125] BOJ / G4 / 호텔 / 강신지
2 parents 88e06dd + 7d87bae commit e49eccd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

25 BOJ 호텔.md

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

0 commit comments

Comments
 (0)