-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
38 lines (32 loc) · 738 Bytes
/
test.cpp
File metadata and controls
38 lines (32 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;
const long long INF = 1e12;
int main() {
int n, m;
cin >> n >> m;
vector<int> house(n);
for (int i = 0; i < n; i++) {
cin >> house[i];
}
sort(house.begin(), house.end());
long long left = 0, right = INF;
while(right - left > 1) {
long long x = (left + right) / 2;
int cnt = 1;
int prev = 0;
for (int i = 0; i < n; i++) {
if (house[i] - house[prev] >= x) {
cnt++;
prev = i;
}
}
if (cnt >= m) left = x;
else right = x;
}
cout << left << endl;
return 0;
}