File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ int D = Integer . parseInt(st. nextToken());
10+ int P = Integer . parseInt(st. nextToken());
11+ int [][] pipe = new int [P ][2 ];
12+ for (int i= 0 ; i< P ;i++ ){
13+ st = new StringTokenizer (br. readLine());
14+ pipe[i][0 ]= Integer . parseInt(st. nextToken());
15+ pipe[i][1 ]= Integer . parseInt(st. nextToken());
16+ }
17+ int [] dp= new int [D + 1 ];
18+ int INF = Integer . MAX_VALUE ;
19+ dp[0 ]= INF ;
20+
21+ for (int i = 0 ; i< P ; i++ ){
22+ int l = pipe[i][0 ];
23+ int c = pipe[i][1 ];
24+ for (int j = D ; j>= l; j-- ){
25+ if (dp[j- l]<= 0 ){
26+ continue ;
27+ }
28+ dp[j] = Math . max(dp[j], Math . min(dp[j- l], c));
29+ }
30+ }
31+ System . out. println(dp[D ]);
32+ }
33+ }
34+
35+ ```
You can’t perform that action at this time.
0 commit comments