-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJW_43238.java
More file actions
28 lines (26 loc) Β· 960 Bytes
/
JW_43238.java
File metadata and controls
28 lines (26 loc) Β· 960 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
import java.util.Arrays;
class JW_43238 {
public long solution(int n, int[] times) {
Arrays.sort(times); // μ΄λΆ νμμ μν μ λ ¬
long l = 1, r = (long) times[times.length - 1] * n; // κ°λ₯ν μ΅μ, μ΅λ μκ°
// λ§€κ° λ³μ νμ
while (l <= r) {
long m = (l + r) / 2; // λ§€κ° λ³μ
if (isPossible(times, n, m)) { // κ²°μ ν¨μ
// μ΅μκ°μ μ°ΎκΈ° μν΄ μΌμͺ½ νμ
r = m - 1;
} else {
l = m + 1;
}
}
return l; // Lower Bound λ°ν
}
// κ²°μ ν¨μ : target μκ°μ κ°κ°μ μ¬μ¬κ΄μ΄ λͺ λͺ
μ μ¬μ¬ν μ μλμ§
private boolean isPossible(int[] times, int n, long target) {
long cnt = 0;
for (int time : times) {
cnt += target / (long) time;
}
return cnt >= n; // nλͺ
μ΄μ μ¬μ¬νλ€λ©΄ true
}
}