CodeChef: Practical coding for everyone

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 --------------//

@isparshp
your logic looks fine amy be failing for some edge cases .
this is my solution .
plzz refer for debugging.

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,h;
	    cin>>n>>h;
	    int a[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    int lo=1,hi=1e9;
	    int ans=0;
	    while(lo<=hi)
	    {
	        int mid=lo+(hi-lo)/2;
	        int cnt=0;
	        for(int i=0;i<n;i++)
	        {
	            cnt+=(ceil(a[i]*1.0/mid*1.0));
	        }
	        if(cnt<=h)
	        {
	        ans=mid;     
	        hi=mid-1;
	        }
	        else
	        lo=mid+1;
	    }
	    cout<<ans<<endl;
	}
	return 0;
}