-
boj)1654 - 랜선 자르기PS/boj 2020. 11. 17. 17:3112345678910111213141516171819202122232425262728293031323334353637383940414243444546import java.io.*;import java.util.*;public class boj_1654 {static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));static StringTokenizer st;static long[] len;static int k, n;public static void main(String[] args) throws IOException {st = new StringTokenizer(br.readLine());k = Integer.parseInt(st.nextToken());n = Integer.parseInt(st.nextToken());len = new long[k];for (int i = 0; i < k; i++) {len[i] = Integer.parseInt(br.readLine());}Arrays.sort(len);long left = 1;long right = len[len.length-1];long ans = 0;while (left <= right) {long mid = (left + right) / 2;long cnt = 0;for (int i = 0; i < k; i++) {cnt += len[i] / mid;}if (cnt >= n) {ans = Math.max(mid, ans);left = mid + 1;} else {right = mid - 1;}}System.out.println(ans);}}
cs - 이분탐색
- 아 이분탐색인거 알았는데 끝까지 해결 못했다...
'PS > boj' 카테고리의 다른 글
boj)15654 - N과 M (5) (0) 2020.11.17 boj)15652 - N과 M (4) (0) 2020.11.17 boj)5525 - IOIOI (0) 2020.11.17 boj)15651 - N과 M (3) (0) 2020.11.16 boj)15650 - N과 M (2) (0) 2020.11.16