-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2110.cpp
More file actions
37 lines (29 loc) · 681 Bytes
/
2110.cpp
File metadata and controls
37 lines (29 loc) · 681 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
#include <bits/stdc++.h>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std ;
int N, C ;
bool BinSearch(int mid, vector<int> &arr)
{
int prev = -mid-1, cnt = C ;
for(int &it : arr)
if(it - prev >= mid) prev = it, cnt--;
return cnt <= 0 ;
}
int main()
{
SETTING ;
cin >> N >> C ;
vector<int> arr(N) ;
for(int &it : arr)
{
cin >> it ;
}
sort(arr.begin(), arr.end()) ;
register int low = 0, high = arr.back() - arr.front() ;
while(low != high)
{
int mid = (low + high + 1) >> 1 ;
BinSearch(mid, arr) ? low = mid : high = mid - 1 ;
}
cout << low ;
}