-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2110.cpp
More file actions
41 lines (35 loc) · 650 Bytes
/
Copy path2110.cpp
File metadata and controls
41 lines (35 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "stdafx.h"
#include <stdlib.h>
int a[100], n, m;
int cmp(const void *u, const void *v) {
if (*(int*)u > *(int*)v) return 1;
else return -1;
}
bool com(int x) {
int cnt = 1;
int back = a[0];
for (int i = 1; i < n; i++)
if (a[i]-back >= x) {
cnt++;
back = a[i];
}
return cnt >= m;
}
int main() {
int r, l, mid, ans = 1;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
qsort(a, n, sizeof(int), cmp);
r = a[n - 1] - a[0];
l = 1;
while (r >= l) {
mid = (r + l) / 2;
if (com(mid)) {
if (ans <= mid) ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
printf("%d\n", ans);
return 0;
}