File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8+ StringTokenizer st = new StringTokenizer (br .readLine ());
9+ int N = Integer .parseInt (st .nextToken ());
10+ int C = Integer .parseInt (st .nextToken ());
11+
12+ int [] house = new int [N ];
13+ for (int i = 0 ; i < N ; i ++) {
14+ house [i ] = Integer .parseInt (br .readLine ());
15+ }
16+ Arrays .sort (house );
17+ int left = 1 ;
18+ int right = house [N - 1 ] - house [0 ];
19+ int answer = 0 ;
20+ while (left <= right ) {
21+ int mid = (left + right ) / 2 ;
22+ int index = 0 ;
23+ int count = 1 ;
24+ for (int i = 0 ; i < N ; i ++) {
25+ if (house [i ] - house [index ] >= mid ) {
26+ index = i ;
27+ count ++;
28+ }
29+ }
30+ if (count < C ) {
31+ right = mid - 1 ;
32+ } else {
33+ answer = mid ;
34+ left = mid + 1 ;
35+ }
36+ }
37+ System .out .println (answer );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments