forked from saltfactory/kakao.github.io
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patha.cpp
56 lines (49 loc) · 970 Bytes
/
a.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cassert>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
int n, c;
ll a[200002];
bool feasible(int dst) {
int prv = 1, cnt = 1;
for (int i = 1; i <= n; i++) {
if (a[i]-a[prv] >= dst) {
cnt++;
prv = i;
}
}
return cnt >= c;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> c;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a+1, a+n+1);
int lft = 1, rgt = a[n]-a[1];
int ans = -1;
while (lft <= rgt) {
int mid = (lft+rgt+1)/2;
if (feasible(mid)) {
ans = mid;
lft = mid+1;
}
else {
rgt = mid-1;
}
}
cout << ans << "\n";
return 0;
}