-
Notifications
You must be signed in to change notification settings - Fork 0
/
AGGRCOW.cpp
54 lines (49 loc) · 1.02 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
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
bool count(int arr[],int n,int val,int c)
{
int cow=1,qty=arr[0];
for(int i=1;i<n;i++)
{
if(arr[i]-qty>=val)
{
cow++;
qty=arr[i];
if(cow==c)
return true;
}
}
return false;
}
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
int n,c;
cin>>n>>c;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
int beg=arr[0],end=arr[n-1],max=-1;;
while(beg<=end)
{
//cout<<beg<<" "<<end<<"\n";
int mid=(beg+end)/2;
if(count(arr,n,mid,c))
{
beg=mid+1;
if(max<mid)
max=mid;
}
else
end=mid-1;
}
cout<<max<<"\n";
}
}