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
41 changes: 41 additions & 0 deletions suyeun84/202502/11 BOJ G5 창영이와 커피.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
```java
import java.util.*;
import java.io.*;

class Solution
{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
Integer[] coffee = new Integer[N];
int[] dp = new int[K+1];
Arrays.fill(dp, Integer.MAX_VALUE);
dp[0] = 0;
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
coffee[i] = Integer.parseInt(st.nextToken());
}

Arrays.sort(coffee, Collections.reverseOrder());

for (int i = 0; i < N; i++) {
if (coffee[i] > K) continue;
dp[coffee[i]] = 1;
for (int j = K; j > coffee[i]; j--) {
if (dp[j - coffee[i]] != Integer.MAX_VALUE) {
dp[j] = Math.min(dp[j], dp[j - coffee[i]] + 1);
}
}
}
Comment on lines +23 to +31
Copy link
Contributor

Choose a reason for hiding this comment

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

옹 이런 방법도... 배워갑니다


if (dp[K] != Integer.MAX_VALUE) {
System.out.println(dp[K]);
} else {
System.out.println(-1);
}
}
}

```