-
Notifications
You must be signed in to change notification settings - Fork 67
/
AGGRCOW.cpp
52 lines (43 loc) · 1.03 KB
/
AGGRCOW.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
#include <bits/stdc++.h>
using namespace std;
/*
O(T * N * log(MAX_VALUE)) solution via binary search
Solution from 2016...
*/
#define Long long long
#define ld long double
#define pii pair<int, int>
#define pli pair<Long, int>
const int me = 100025;
const int mod = 0x3b9aca07;
int t, n, c;
int a[me];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while(t --){
cin >> n >> c;
for(int i = 0; i < n; i ++)
cin >> a[i];
sort(a, a + n);
int low = 0, high = 1.e9, mid, best = 0;
while(low <= high){
mid = (low + high + 1) / 2;
int cnt = 1, last = 0;
for(int i = 1; i < n && cnt < c; i ++){
if(a[i] - a[last] >= mid)
last = i, cnt ++;
}
if(cnt >= c){
best = mid;
low = mid + 1;
}
else{
high = mid - 1;
}
}
cout << best << endl;
}
return 0;
}