0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

#532. 【2018年6月多校联训B组day6】借书

https://sjzezoj.com/submission/17025
This commit is contained in:
Baoshuo Ren 2021-08-14 15:13:00 +08:00 committed by Baoshuo Ren
parent 9958ed5e5d
commit 37c2368a5b
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

46
S2OJ/532/532.cpp Normal file
View 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;
}