-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAGGRCOW.cpp
56 lines (45 loc) · 870 Bytes
/
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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
int arr[a + 1];
for(int j = 1; j <= a; j++){
cin >> arr[j];
}
sort(arr + 1, arr + a);
int left = 1;
int right = arr[a];
int fm = -1;
while(left <= right){
int meio = (left + right) / 2;
int dis = 0;
int longe = 0;
for(int j = 1; j <= a; j++){
if(j == 1){
longe++;
continue;
}
if(dis >= meio){
dis = 0;
longe++;
}
dis += arr[j] - arr[j - 1];
}
if(dis >= meio){
dis = 0;
longe++;
}
if(longe >= b){
left = meio + 1;
fm = meio;
}else{
right = meio - 1;
}
}
cout << fm << endl;
}
}