#include <cstdio>
#include <algorithm>

using namespace std;

int x[100005]={};

int main()
{
    int n,c;
    scanf("%d %d",&n,&c);

    for(int i=0; i<n; i++)
    {
        scanf("%d",&x[i]);
    }

    sort(x,x+n);
    
    int gld=0;
    for(int i=1,j=x[n-1]-x[0]; i<=j; )
    {
        int m=(i+j)/2;
        int ct=1;
        int lc=x[0];

        for(int k=1; k<n; k++)
        {
            if(x[k]-lc>=m)
            {
                ct++;
                lc=x[k];
            }
        }

        if(ct>=c)
        {
            gld=m;
            i=m+1;
        }
        else
        {
            j=m-1;
        }
        
    }
    printf("%d",gld);
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: