#include
#include
using namespace std;
int isValid(long stalls[],int n,int s,int current_ans){
int cow = 1;
int currently_alloted = stalls[0];
for(int i=1;i<n;i++){
if(stalls[i]-currently_alloted >= current_ans){
cow++;
if(cow==s){
return 1;
}
currently_alloted = stalls[i];
}
}
return 0;
}
long minDist(long stalls[],int n,int k){
int s = stalls[0];
int e = stalls[n-1];
int ans = 0;
int mid = 0;
while(s+1<e){
mid = (s+e)/2;
if(isValid(stalls,n,k,mid)==1){
s = mid;
}
else{
e = mid;
}
}
return s;
}
int main(){
int n,k;cin>>n>>k;
long stalls[n]={0};
for(int i=0;i<n;i++)
{
cin>>stalls[i];
}
long int p=0;
p=minDist(stalls,n,k);
cout<<p<<endl;
return 0;
}
i tried the question myself.i was failing in 1 test case.
i copied the editorial and checked that test case.it is giving diffrent answer.the test case is 3.