About aggressive cows

#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool canplace(ll a[],int n,ll max,int cow){
int i;
int cnt=1;
ll last=a[0];
for( i=1;i<n;i++)
{
if(a[i]-last>=max)
{
last=a[i];
cnt++;
if(cnt==cow)
return true;
}
}

return false;

}

int main()
{
int t;
cin>>t;
while(t–){

 int n,no;
    cin>>n>>no;
    ll a[n]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll max=a[n-1]-a[0];
     ll s=0;
    ll ans;
    	ll e=max;
    while(s<=e){
        ll mid=(s+e)/2;
        if(canplace(a,n,mid,no))
        {
            ans=mid;
            s=mid+1;
        }
        else
            e=mid-1;
        
    }

cout<<ans<<endl;

}
    return 0;

}

my my this code get TLE for the que aggresive cow why

I have edited your code… Try to submit it now…