https://www.spoj.com/problems/MAIN8_C/#:~:text=among%20his%20K%20(1<%3D,1000000000)%20IIIT-Delhi%20students.&text=way%20such%20that%3A-,Shaky%20has%20N%20(1<%3DN<%3D50000),1000000000)%20IIIT%2DDelhi%20students.
Can please some one help me with this problem I am passing the given test cases but I am not getting accepted.
This is my solution:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool ifPossible(ll a[],int n,ll k,ll mid){
ll totalNumOfStudent = 0;
if(mid==0){
return false;
}
for(int i=0;i<n;i++){
totalNumOfStudent+=(a[i]/mid);
}
return totalNumOfStudent>=k;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t–){
int n;
ll k;
cin>>n;
cin>>k;
ll a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
ll start = 0;
ll end = a[n-1];
ll ans = start;
while(start<=end){
ll mid = (start+end)/2;
bool possible = ifPossible(a,n,k,mid);
if(possible){
ans = mid;
start = mid+1;
}
else{
end = mid-1;
}
}
cout<<ans<<"\n";
}
}