Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions boj/solved/dp/2073/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.io.*;
import java.util.*;

class Main {
static int D, P;
static int[][] pipes;
static int[] dp;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
D = Integer.parseInt(st.nextToken());
P = Integer.parseInt(st.nextToken());
pipes = new int[P][2];
dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량

for(int i = 0;i<P;i++) {
st = new StringTokenizer(br.readLine());
pipes[i][0] = Integer.parseInt(st.nextToken());
pipes[i][1] = Integer.parseInt(st.nextToken());
}

Arrays.sort(pipes, Comparator.comparing(a -> a[0]));
dp[0] = 100001;
for(int[] pipe : pipes) {
int d = pipe[0];
int p = pipe[1];

for(int i = D;i>= d;i--){ // 더해서 i가 될때
dp[i] = Math.max(dp[i], Math.min(p, dp[i-d]));
}
}
System.out.println(dp[D]);
}
}