-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPOJ AGGRCOW.cpp
69 lines (51 loc) · 1.11 KB
/
SPOJ 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
#include <bits/stdc++.h>
#define pb push_back
#define lp(p,n) for(int p=0; p<n; p++)
using namespace std;
bool can(vector<int> x, int n, int space){
int pos=x[0];
int currcount=1;
for(int i=1; i<x.size(); i++){
if(currcount>=n) return true;
if(x[i]-pos>=space){
currcount++;
pos=x[i];
}
}
if(currcount>=n) return true;
return false;
}
int maxspace(vector <int> place, int n){
int low=1, high=1e9;
int mid;
while(low<high){
if(high-low==1){
if(can(place,n,high)){
return high;
}else{
high--;
}
}
mid=low+(high-low)/2;
if(can(place,n,mid)){
low=mid;
}else{
high=mid-1;
}
}
return high;
}
int main(){
int t;
scanf("%d", &t);
while(t--){
int n,c;
scanf("%d%d",&n ,&c);
vector <int> places(n);
lp(i,n){
scanf("%d", &places[i]);
}
sort(places.begin(),places.end());
printf("%d\n",maxspace(places,c));
}
}