Aggressive cow (tle)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll isvalid(ll arr[],ll n,ll cows,ll mid)
{
ll pos=arr[0];
ll c=1;
for(ll i=1;i<n;i++)
{
if(arr[i]-pos>=mid)
{
c++;
pos=arr[i];
if(c==cows)
{
return 1;

        }
    }
}
return 0;

}
ll binarysearch( ll arr[],ll n,ll cows)
{
ll start=0,end=arr[n-1];
ll final=0;
ll mid;
while(start<=end)
{
mid=(start+end)/2;
if(isvalid(arr,n,cows,mid))
{ final=max(final,mid);
start=mid+1;

    }
    else{
        end=mid-1;

    }
}
return final;

}

int main() {
ll t;
cin>>t;
while(t–)
{
ll n;
cin>>n;
ll cows;
cin>>cows;
ll arr[n];
for(ll i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);
ll k=binarysearch(arr,n,cows);
cout<<k<<endl;
}
return 0;
}
// why this code is showing tle,

brooo , there is just 1 test case
remove the while loop for the no of test cases
otherwise the code is fine