코드를 입력하세요
function solution(n, times) {
const sortTimes = times.sort((a, b) => a - b)
let left = 1
let right = sortTimes[sortTimes.length - 1] * n
while (left <= right) {
const mid = Math.floor((left + right) / 2)
const sum = times.reduce((acc, item) => acc + Math.floor(mid / item), 0)
if (sum < n) {
left = mid + 1
} else {
right = mid - 1
}
}
return left
}
=> 대표적인 결정문제 = 이진탐색 = 파라메트릭서치 문제이다. 최소 시간 안에 입국 심사를 해야하는데, 1 ~ 제일 늦게 하는 사람 * 사람 수까지에서 이진 탐색으로 찾으면 된다. 사람 수를 구하면서 mid를 갱신하면 된다.