File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments