Skip to content

Commit 5bf773a

Browse files
authored
Merge pull request #1087 from AlgorithmWithGod/LiiNi-coder
[20251010] BOJ / G4 / 수도배관공사 / 이인희
2 parents 99fe269 + 7d1bdd4 commit 5bf773a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
```

0 commit comments

Comments
 (0)