-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAGGRCOW.cpp
78 lines (63 loc) · 1.44 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <algorithm>
#include <limits.h>
#include <cstring>
#include <cmath>
#define ll long
#define get(a) scanf("%ld", &a)
#define rep(n) for( ll i = 0; i < n; i++ )
#define repVector(v) for(vector<ll>::iterator it = v.begin(); it != v.end(); it++ )
#define all(c) c.begin(), c.end()
#define repu(a,n) for( ll i = a; i < n; i++ )
#define max(a,b) a > b ? a : b
#define pb push_back
using namespace std;
vector<ll> v;
ll n, k;
bool func( ll mid ) {
ll first = v[0];
ll count = 1;
rep( v.size() ) {
if( v[i] - first >= mid )
{ count++; first = v[i]; }
if( count >= k )
return 1;
}
return 0;
}
ll binsearch( ll top, ll rear ) {
int mid = top + rear;
mid /= 2;
//cout << "( " << top << " , " << rear << " )";
if( top >= rear ) {
return top-1;
}
ll r = func(mid);
if( r == 1 )
return binsearch( mid+1, rear );
else if( r == 0 )
return binsearch( top, mid );
}
int main() {
ll t;
get(t);
while(t--) {
get(n); get(k);
v.clear();
ll max = 0;
rep(n) {
ll x;
get(x);
v.pb(x);
max = max > x ? max : x;
}
sort( all(v) );
printf("%ld\n", binsearch(0, max-1) );
}
}