-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAGGRCOW.cpp
More file actions
53 lines (49 loc) · 820 Bytes
/
AGGRCOW.cpp
File metadata and controls
53 lines (49 loc) · 820 Bytes
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
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define pb push_back
int t,n,c,l,r,inp,mid;
vector <int> a;
bool check(int x)
{
int temp=a[0],cnt=0;
for(int i=1;i<n;i++)
{
if(a[i]-temp >= x)
{
cnt++;
temp=a[i];
}
}
if(cnt >= c)
return true;
return false;
}
int main()
{
cin>>t;
while(t--)
{
a.clear();
cin>>n>>c;
c--;
for(int i=0;i<n;i++)
{
cin>>inp;
a.pb(inp);
}
sort(a.begin(),a.end());
l=0;
r=a[n-1];
while(l<=r)
{
mid=(l+r)/2;
if( check(mid) )
l=mid+1;
else
r=mid-1;
}
cout<<l-1<<"\n";
}
}