知识点:二分
这个是两种最基本的二分之一,最大化最小值,也就是从左向右的二分,
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
const int N = 1e5 + 5;
int n, m, a[N];
bool check(int x) {
int cnt = 1;
int pos = a[0];
for (int i = 1; i < n; i++) {
if (a[i] - pos >= x) { cnt++; pos = a[i]; }
}
return cnt >= m;
}
void solve(int l, int r) {
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l << endl;
}
int main() {
cin >> n >> m;
int t = 0;
for (int i = 0; i < n; i++) { cin >> a[i]; t = max(t, a[i]); }
sort(a, a + n);
solve(0, t);
return 0;
}