help am not getting WA only one test case: #include<bits/stdc++.h>
using namespace std;
//------------------Definition --------------//
define ll long long
define fn() for(ll i=1;i<=n;i++)
define fm() for(ll i=1;i<=m;i++)
define actionbeam cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
define testcase int t;cin>>t;while(t–)
define arrayInput for(int i=0;i<n;i++) cin>>arr[i]
define brrayInput for(int i=0;i<n;i++) cin>>brr[i]
define nahi cout<<“NO”<<endl
define haan cout<<“YES”<<endl
ll arr[100100];
ll n,h;
//-------------------GCD ------------------//
int gcd(int a, int b)
{
if(b==0) return a;
return gcd(b,a%b);
}
//------------------- Binary Power ------------------//
long long binpow(long long a, long long b) {
if (b == 0)
return 1;
long long res = binpow(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
//-----------------Linear Diophantine Equations (aX+bY=c) ----------------//
int lde(int a, int b, int& x, int& y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = lde(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
//------------------Main --------------//
ll check(ll mid)
{
ll count=0;
for (int i = 0; i < n; i++) {
if(arr[i]<=mid)
{
count++;
}
else
{
if(count%mid)
{
count+=arr[i]/mid;
}
else
{
count+=(arr[i]/mid+1);
}
}
}
return count>h;
}
void solve()
{
cin>>n>>h;
ll sum=0;
for (ll i = 0; i < n; i++) {
cin>>arr[i];
sum+=arr[i];
}
ll lo=1;
ll hi=sum;
ll ans=-1;
while(lo<=hi)
{
ll mid=lo + (hi-lo)/2;
if(check(mid))
{
lo=mid+1;
}
else
{
ans=mid;
hi=mid-1;
}
}
cout<<ans<<endl;
}
int main()
{
actionbeam
ll t;
cin >> t;
while(t–)
{
solve();
}
return 0;
}
//------------------ CP TEMPLATE BY SPARSH PRAKASH --------------//