-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2110.cpp
More file actions
64 lines (53 loc) · 812 Bytes
/
2110.cpp
File metadata and controls
64 lines (53 loc) · 812 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#define INF 9999999999;
using namespace std;
int n;
int c;
vector<int>v;
int res = 0;
void share(int start, int end) {
int cnt = 1;
int temp = v[0];
if (start + 1 >= end) {
for (int i = 0; i < n; i++) {
if (v[i] - temp >= end) {
cnt++;
temp = v[i];
}
}
if (cnt >= c) {
cout << end;
}
else {
cout << start;
}
return;
}
int mid = (end + start)/2;
for (int i = 0; i < n; i++) {
if (v[i] - temp >= mid) {
cnt++;
temp = v[i];
}
}
if (cnt >= c) {
share(mid, end);
}
else {
share(start, mid);
}
}
int main() {
cin >> n >> c;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
share(1, v[n-1]-v[0]);
}