문제링크
https://www.acmicpc.net/problem/1654
나의코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int K = Integer.parseInt(st.nextToken());
int N = Integer.parseInt(st.nextToken());
int[] arr = new int[K];
long max = 0;
for(int i = 0; i < K; i++){
arr[i] = Integer.parseInt(br.readLine());
if(max < arr[i]){
max = arr[i];
}
}
max = max + 1;
long min = 0;
long mid = 0;
while(min < max){
long count = 0;
mid = (max + min) / 2;
for(int i = 0; i < K; i++){
count = count + (arr[i] / mid);
}
if(count < N){
max = mid;
}else{
min = mid + 1;
}
}
System.out.print(min - 1);
}
}
'Baekjoon Online Judge' 카테고리의 다른 글
[BOJ] 백준 1874번: 스택 수열 (Java) (0) | 2023.04.04 |
---|---|
[BOJ] 백준 1436번: 영화감독 숌 (Java) (0) | 2023.04.02 |
[BOJ] 백준 1259번: 팰린드롬수 (Java) (0) | 2023.04.01 |
[BOJ] 백준 1181번: 단어 정렬 (Java) (0) | 2023.03.31 |
[BOJ] 백준 1018번: 체스판 다시 칠하기 (Java) (0) | 2023.03.30 |
댓글