Skip to content

Commit b246017

Browse files
authored
[20250212] BOJ / G5 / 창영이와 커피 / 권혁준
1 parent fb87766 commit b246017

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st;
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() {return Integer.parseInt(st.nextToken());}
15+
static long nextLong() {return Long.parseLong(st.nextToken());}
16+
static void bwEnd() throws Exception {bw.flush();bw.close();}
17+
18+
// Additional field
19+
static int[] dp;
20+
static int N, K;
21+
22+
public static void main(String[] args) throws Exception {
23+
24+
//ready();
25+
solve();
26+
27+
bwEnd();
28+
}
29+
30+
static void ready() throws Exception{
31+
32+
33+
}
34+
35+
static void solve() throws Exception{
36+
37+
nextLine();
38+
N = nextInt();
39+
K = nextInt();
40+
dp = new int[100001];
41+
Arrays.fill(dp, Integer.MAX_VALUE-1);
42+
dp[0] = 0;
43+
nextLine();
44+
while(N-- > 0) {
45+
int now = nextInt();
46+
for(int j=100000;j>now;j--) if(dp[j-now] != 0) dp[j] = Math.min(dp[j-now]+1, dp[j]);
47+
dp[now] = 1;
48+
}
49+
bw.write((dp[K] == Integer.MAX_VALUE-1 ? -1 : dp[K]) + "\n");
50+
51+
52+
}
53+
54+
}
55+
56+
```

0 commit comments

Comments
 (0)