My issue
I find my logic is good with good with sample test cases but I don’t know what’s happening all other test cases
My code
#include <bits/stdc++.h>
using namespace std;
int h;
const int N= 1e5 +10;
bool predicate(vector<int>& a,int k){
int hr=0;
for (auto x : a){
hr+=x/k+((x%k==0)?0:1);
}
return hr<=h;
}
int main() {
// your code goes here
int t,temp;
int n;
cin>>t;
while(t--){
vector<int> a;
cin>>n>>h;
for (int i=0;i<n;i++){
cin>>temp;
a.push_back(temp);
}
int l=1,r=n,m;
while(r-l>1){
m=(l+r)/2;
if(predicate(a,m)) r=m;
else l=m+1;
}
if(predicate(a,l)) cout<<l<<endl;
else cout<<r<<endl;
}
return 0;
}
Problem Link: MINEAT Problem - CodeChef