-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcandies_distribution.cpp
More file actions
54 lines (50 loc) · 981 Bytes
/
candies_distribution.cpp
File metadata and controls
54 lines (50 loc) · 981 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
54
nclude<bits/stdc++.h>
using namespace std;
bool distributed(long long ar[],long long n,long long k,long long mid)
{
long long persons=0;
for(int i=0;i<n;i++)
{
persons+=ar[i]/mid;
}
if(persons>=k)
{
return true;
}
return false;
}
int main() {
// Write your code here
int t;
cin>>t;
while(t--)
{
long long n,k;
cin>>n>>k;
long long ar[n];
long long min=1;
long long max=-1;
for(int i=0;i<n;i++)
{
cin>>ar[i];
if(ar[i]>max)
{
max=ar[i];
}
}
long long ans=0;
while(min<=max)
{
int mid=min+(max-min)/2;
if(distributed(ar,n,k,mid))
{
ans=mid;
min=mid+1;
}
else
{
max=mid-1;
}
}
cout<<ans<<endl;
}