Showing wrong ans

#include
using namespace std;

bool poss(int a[],int n,int c,int m){
int cows=1;
int d=a[0];
for(int i=1;i<n;i++){
if(a[i]-d>=m){
cows++;
d=a[i];
if(cows==c){
return true;
}
}
}

return false;

}

int main() {
int n,c;
cin>>n>>c;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int e=a[n-1]-a[0];
int ans=0;
int s=0;
while(s<=e){
int mid=(s+e)/2;
if(poss(a,n,c,mid)){
ans=mid;
s=mid+1;
}
else{
e=mid-1;
}
}
cout<<ans<<endl;

return 0;

}

hello @mansi25

check now->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.