Works on hackerBlocks but not on SPOJ

Wrong Answer on SPOJ

#include< bits/stdc++.h >

typedef long long ll;
using namespace std;

bool placeCow(ll min ,vector &arr,ll n,ll c)
{
ll count=1;
ll last=0;
for(ll i=1;i<n;i++)
{
if(arr[i]-arr[last]>=min)
{
last=i;
count++;
if(count==c)
return true;
}

}
return false;

}

ll minDist(vector &arr,ll n ,ll c)
{

ll s=0,e=arr[n-1]-arr[0];
ll ans=0;
while(s<=e)
{
    ll mid=s+((e-s)/2);
    if(placeCow(mid,arr,n,c))
    {
        ans=mid;
        s=mid+1;
    }
    else
    {
            e=mid-1;
    }
    
}
return ans;

}

int main()
{
ll t;
cin>>t;
while(t–)
{
ll n,c;
cin>>n>>c;
vector arr(n);
for(ll i=0;i<n;i++)
cin>>arr[i];
sort(arr.begin(),arr.end());
cout<<minDist(arr,n,c);
}
}

Hello @saswat1908,

Please, share your code using Online Coding Blocks IDE.
The way you have shared it has introduced many syntax errors to it.
So, i cannot differentiate between the actual error and the errors due sharing technique.

STEPS:

  1. Paste it at https://ide.codingblocks.com/
  2. Save it there.
  3. Share the URL generated.

For reference you can compare with my code and we have followed the same logic:
https://ide.codingblocks.com/s/213559

Hope, this would help.
Give a like if you are satisfied.

Hello @saswat1908,

I have corrected the code that you have shared.
It had two mistakes:


Refer to comments for better understanding.

Hope, this would help.
Give a like if you are satisfied.