File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments