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 거리르 구하는 최대 수도관 용량

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에 오타가 있습니다: "거리르" → "거리를"

Suggested change
dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량
dp = new int[D+1]; // idx 거리를 구하는 최대 수도관 용량

Copilot uses AI. Check for mistakes.

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에 오타가 있습니다: "idx 거리를 구하는" → "idx 거리까지 도달할 때"가 더 명확합니다. 현재 주석은 의미가 불명확합니다. DP 배열이 "특정 거리까지 도달할 때 가능한 최대 최소 용량"을 저장한다는 것을 명확히 표현해야 합니다.

Suggested change
dp = new int[D+1]; // idx 거리르 구하는 최대 수도관 용량
dp = new int[D+1]; // idx 거리까지 도달할 때 가능한 최대 최소 수도관 용량을 저장

Copilot uses AI. Check for mistakes.

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;

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

초기값 100001은 매직 넘버입니다. 의미를 명확히 하기 위해 상수로 선언하는 것이 좋습니다. 예: static final int INF = 100001; 또는 주석으로 "문제의 최대 용량 제약(100000)보다 큰 값"임을 명시해야 합니다.

Copilot uses AI. Check for mistakes.
for(int[] pipe : pipes) {
int d = pipe[0];
int p = pipe[1];

for(int i = D;i>= d;i--){ // 더해서 i가 될때

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에 띄어쓰기 오류가 있습니다: "더해서 i가 될때" → "더해서 i가 될 때"

Suggested change
for(int i = D;i>= d;i--){ // 더해서 i가 될때
for(int i = D;i>= d;i--){ // 더해서 i가 될 때

Copilot uses AI. Check for mistakes.

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] 띄어쓰기가 누락되었습니다: i>=i >=

Suggested change
for(int i = D;i>= d;i--){ // 더해서 i가 될때
for(int i = D; i >= d; i--){ // 더해서 i가 될때

Copilot uses AI. Check for mistakes.
dp[i] = Math.max(dp[i], Math.min(p, dp[i-d]));
Comment on lines +25 to +29

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명 dp가 너무 짧고 모호합니다. lengthcapacity 또는 pipeLengthpipeCapacity로 변경하면 가독성이 향상됩니다.

Suggested change
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]));
int length = pipe[0];
int capacity = pipe[1];
for(int i = D; i >= length; i--){ // 더해서 i가 될때
dp[i] = Math.max(dp[i], Math.min(capacity, dp[i-length]));

Copilot uses AI. Check for mistakes.
}
}
System.out.println(dp[D]);
}
}