-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path44.cpp
More file actions
44 lines (36 loc) · 766 Bytes
/
44.cpp
File metadata and controls
44 lines (36 loc) · 766 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
#include<iostream>
#include<vector>
using namespace std;
#define SIZE 200001
int arr[SIZE], n;
int cal(int len){
int cnt = 1, pos = arr[0];
for(int i = 1; i < n; i++){
if(arr[i] - pos >= len){
cnt++;
pos = arr[i];
}
}
return cnt;
}
int main(){
freopen("input.txt", "rt", stdin);
int c, lt = 0, rt = -2147000000, mid = 0, res = 0;
cin>>n>>c;
for(int i = 0; i < n; i++){
cin>>arr[i];
if(arr[i] > rt) rt = arr[i];
}
sort(arr, arr+n);
while(lt <= rt){
mid = (lt + rt) / 2;
if(cal(mid) >= c){
res = mid;
lt = mid + 1;
}else{
rt = mid - 1;
}
}
cout<<res<<"\n";
return 0;
}