Skip to content

Commit e196038

Browse files
committed
84차 2번 문제풀이
1 parent 105ed24 commit e196038

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

live8/test84/문제2/황장현.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,25 @@ const input = require('fs')
77

88
function solution(input) {
99
const [K, N] = input[0];
10-
const lanList = input.slice(1).flat();
11-
if (K >= N) return Math.max(...lanList);
10+
const lanList = input.slice(1);
11+
12+
let low = 1;
13+
let high = Math.max(...lanList);
14+
let answer = 0;
15+
16+
while (low <= high) {
17+
let mid = Math.floor((low + high) / 2);
18+
let count = lanList.reduce((acc, cur) => acc + Math.floor(cur / mid), 0);
19+
20+
if (count >= N) {
21+
answer = mid;
22+
low = mid + 1;
23+
} else {
24+
high = mid - 1;
25+
}
26+
}
27+
28+
return answer;
1229
}
1330

1431
console.log(solution(input));

0 commit comments

Comments
 (0)