#include<stdio.h> #include<algorithm> #include<iostream> usingnamespacestd; char ch_buffer; bool signum; inlinevoidreadInt(int &l){ l = 0; do ch_buffer = getchar(); while ((ch_buffer < '0' || ch_buffer > '9') && ch_buffer != '0' && ch_buffer != '-'); if (ch_buffer == '-') ch_buffer = getchar(), signum = true; while (ch_buffer <= '9' && ch_buffer >= '0') l = (l << 3) + (l << 1) + ch_buffer - '0', ch_buffer = getchar(); if (signum) l = -l, signum = false; } #define MAX_N 100005 #define INF 0x7fffffff int x[MAX_N]; int n, c; inlineboolcheck(int m){ int last = 0; for (int i = 1; i < c; i++) { /*当前的牛舍位置*/ int cur = last + 1; while (cur < n && x[cur] - x[last] < m) cur++; /*只放下第一头牛,无法放下第二头牛,使二者的距离大于等于m*/ if (cur == n) returnfalse; last = cur; /*把第i头牛放在编号为cur的牛舍里*/ } returntrue; } intmain(){ ios::sync_with_stdio(false); cin.tie(NULL); readInt(n), readInt(c); for (int i = 0; i < n; i++) readInt(x[i]); sort(x, x + n); int l = 0, r = INF; for (int i = 0; i < 100; i++) { int m = (l + r) >> 1; if (check(m)) l = m; else r = m; } cout << l << endl; return0; }