728x90
문제
코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
private static StringBuilder sb;
private static BufferedReader br;
private static StringTokenizer st;
private static int K,count;
private static int[] arr;
private static int max = -1;
//입력
public static void input() throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
sb = new StringBuilder();
st = new StringTokenizer(br.readLine());
K = Integer.parseInt(st.nextToken());
count = Integer.parseInt(st.nextToken());
arr = new int[K];
for(int i = 0 ; i < K ; i++){
arr[i] = Integer.parseInt(br.readLine());
max = Math.max(max, arr[i]);
}
}
//실행
public static void process() {
long s = 1;
long e = max;
while(s<=e){
long mid = (s+e)/2;
int cnt = 0;
for(int i = 0 ; i < K ; i++){
cnt+=arr[i]/mid;
}
if(cnt>=count){
s = mid+1;
}else{
e = mid-1;
}
}
System.out.println(e);
}
public static void main(String[] args) throws Exception {
input();
process();
}
}
'코딩테스트 > 백준' 카테고리의 다른 글
[Java] 백준 2503번 : 숫자 야구 (0) | 2024.04.15 |
---|---|
[Java] 백준 1816번 : 암호 키 (0) | 2024.04.15 |
[Java] 백준 1546번 : 평균 (0) | 2024.04.14 |
[Java] 백준 2563번 : 색종이 (0) | 2024.04.14 |
[Java] 백준 15593번 : Lifeguards (Bronze) (0) | 2024.04.14 |