-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2110.cpp
More file actions
44 lines (34 loc) · 753 Bytes
/
2110.cpp
File metadata and controls
44 lines (34 loc) · 753 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>
#include<algorithm>
#define N 200005
using namespace std;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, c, i, arr[N];
cin >> n >> c;
for(i=0; i<n; i++) cin >> arr[i];
sort(arr, arr+n);
int l=0, r=arr[n-1]-arr[0];
while(l<r){
int d=arr[0], cc=1;
int key = (l+r+1)/2;
for(i=1; i<n; i++){
if(arr[i]-d>=key){
d=arr[i];
cc++;
}
}
if(cc>c) l=key+1;
else if(cc<c) r=key-1;
else if(r==key) l=key+1;
else l=key;
}
cout << r;
return 0;
}