-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29c0c9b
commit ad6a30d
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |