Skip to content

Commit

Permalink
BOJ_2110 : 공유기 설치
Browse files Browse the repository at this point in the history
  • Loading branch information
spring0913 committed May 10, 2024
1 parent 29c0c9b commit ad6a30d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions week5/BOJ_2110(공유기 설치).java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.*;
import java.util.*;

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 N = Integer.parseInt(st.nextToken());
int C = Integer.parseInt(st.nextToken());

int[] house = new int[N];
for (int i = 0; i < N; i++) {
house[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(house);
int left = 1;
int right = house[N - 1] - house[0];
int answer = 0;
while (left <= right) {
int mid = (left + right) / 2;
int index = 0;
int count = 1;
for (int i = 0; i < N; i++) {
if (house[i] - house[index] >= mid) {
index = i;
count++;
}
}
if (count < C) {
right = mid - 1;
} else {
answer = mid;
left = mid + 1;
}
}
System.out.println(answer);
}
}

0 comments on commit ad6a30d

Please sign in to comment.