Skip to content

Commit 9242f05

Browse files
authored
Merge pull request #249 from AlgorithmWithGod/lkhyun
[20250317] BOJ / 골드4 / 공유기 설치 / 이강현
2 parents cadb7f3 + 4b69de7 commit 9242f05

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
static int N;
7+
static int C;
8+
static int[] arr;
9+
static int max;
10+
public static void main(String[] args)throws Exception{
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
N = Integer.parseInt(st.nextToken());
15+
C = Integer.parseInt(st.nextToken());
16+
arr = new int[N];
17+
for(int i=0;i<N;i++) {
18+
arr[i] = Integer.parseInt(br.readLine());
19+
}
20+
Arrays.sort(arr);
21+
22+
max = binarySearch(0, 1000000000);
23+
bw.write(max+"");
24+
bw.close();
25+
}
26+
public static int binarySearch(int s, int e){
27+
int mid = 0;
28+
while(s<e){
29+
mid = (s+e)/2 + 1;
30+
int cur = arr[0];
31+
int cnt = 1;
32+
for(int i=1;i<N;i++){
33+
if(arr[i]-cur>=mid){
34+
cur = arr[i];
35+
cnt++;
36+
}
37+
}
38+
if(cnt<C){
39+
e = mid-1;
40+
}else{
41+
s = mid;
42+
}
43+
}
44+
return s;
45+
}
46+
}
47+
48+
```

0 commit comments

Comments
 (0)