Skip to content

Commit bab41cc

Browse files
authored
Merge pull request #146 from AlgoLeadMe/6-wonjunYou
6-wonjunYou
2 parents 9c36d72 + 4eb92d4 commit bab41cc

File tree

1 file changed

+37
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)