-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
48 lines (43 loc) · 849 Bytes
/
E.cpp
File metadata and controls
48 lines (43 loc) · 849 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
#include <iostream>
#include <vector>
std::vector<int> array;
int n, k;
bool check(int dist) {
int lastCow = array[0];
int count = 1;
for (int i = 1; i < n; i++) {
if (array[i] - lastCow >= dist) {
lastCow = array[i];
count++;
}
}
bool answer;
if (count >= k){
answer = true;
} else {
answer = false;
}
return answer;
}
int main() {
int succes = 1;
int fail;
int dist;
std::cin >> n >> k;
array.resize(n);
int i = 0;
while(i < n) {
std::cin >> array[i];
i++;
}
fail = array[n - 1];
while (fail - succes > 1) {
dist = (fail + succes) / 2;
if (check(dist)){
succes = dist;
}
else fail = dist;
}
std::cout << succes <<std::endl;
return 0;
}