문제
https://www.acmicpc.net/problem/1654
1654번: 랜선 자르기
첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고 항상 K ≦ N 이다. 그
www.acmicpc.net
풀이
import java.io.*;
import java.util.*;
class Main{
static int k, n;
static int arr[];
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
k = Integer.parseInt(st.nextToken());
n = Integer.parseInt(st.nextToken());
arr = new int[k];
for(int i=0;i<k;i++) {
arr[i] = Integer.parseInt(br.readLine());
}
long l = 1;
long r = Integer.MAX_VALUE;
while(l<r) {
long mid = (l+r+1)/2;
if(solve(mid) < n) {
r = mid-1;
}
else {
l = mid;
}
}
System.out.print(l);
}
static long solve(long val) {
long cnt = 0;
for(int i=0;i<k;i++) {
cnt += arr[i] / val;
}
return cnt;
}
}