mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-17 13:26:47 +00:00
parent
9958ed5e5d
commit
37c2368a5b
46
S2OJ/532/532.cpp
Normal file
46
S2OJ/532/532.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int n, m, a[100005], maxa, f[100005], l, r, mid;
|
||||||
|
|
||||||
|
bool check(int x) {
|
||||||
|
int cnt = 0, ch = 0;
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
ch += f[i];
|
||||||
|
if (ch >= x) {
|
||||||
|
cnt++;
|
||||||
|
ch = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cnt >= m - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin >> n >> m;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> a[i];
|
||||||
|
maxa = max(maxa, a[i]);
|
||||||
|
}
|
||||||
|
sort(a + 1, a + n + 1);
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
f[i] = a[i + 1] - a[i];
|
||||||
|
}
|
||||||
|
l = 1;
|
||||||
|
r = maxa;
|
||||||
|
while (l <= r) {
|
||||||
|
mid = l + r >> 1;
|
||||||
|
if (r - l == 1) {
|
||||||
|
if (check(r)) l = r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (check(mid)) {
|
||||||
|
l = mid;
|
||||||
|
} else {
|
||||||
|
r = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << l << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user