Skip to content

Commit 6235be9

Browse files
committed
BOJ_2792 : 보석 상자
1 parent 7864004 commit 6235be9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

week5/BOJ_2792(보석 상자).java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
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 N = Integer.parseInt(st.nextToken());
10+
int M = Integer.parseInt(st.nextToken());
11+
int[] jewel = new int[M];
12+
int max = Integer.MIN_VALUE;
13+
for (int i = 0; i < M; i++) {
14+
jewel[i] = Integer.parseInt(br.readLine());
15+
max = Math.max(max, jewel[i]);
16+
}
17+
Arrays.sort(jewel);
18+
int answer = max;
19+
int low = 1;
20+
int high = max;
21+
while (low <= high) {
22+
int mid = (low + high) / 2;
23+
int count = 0;
24+
for (int j = 0; j < M; j++) {
25+
count += jewel[j] / mid;
26+
if (jewel[j] % mid != 0) {
27+
count++;
28+
}
29+
}
30+
if (count > N) {
31+
low = mid + 1;
32+
} else {
33+
answer = Math.min(answer, mid);
34+
high = mid - 1;
35+
}
36+
}
37+
System.out.println(answer);
38+
}
39+
}

0 commit comments

Comments
 (0)