forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSB_43238.java
More file actions
31 lines (28 loc) · 864 Bytes
/
SB_43238.java
File metadata and controls
31 lines (28 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
class SB_43238 {
private static boolean canCheck(long target, int[] times, int n) {
long cnt = 0;
for (int tm : times) {
cnt += target / tm;
if (cnt >= n) return true;
}
return false;
}
public static long solution(int n, int[] times) {
Arrays.sort(times);
// 매개변수 탐색, 주어진 시간 내 n명 이상의 사람 처리할 수 있는지
long left = 0;
long right = (long) times[times.length - 1] * n; // 최대 시간
long parm = 0;
while (left <= right) {
long mid = (left + right) / 2;
if (canCheck(mid, times, n)) {
parm = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
return parm;
}
}