Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define boAshraf ios_base::sync_with_stdio(false); cin.tie(NULL);
- #define ll long long
- #define sz(s) (int)(s).size()
- #define all(s) (s).begin(),(s).end()
- using namespace std;
- void File();
- void sol();
- int main() {
- boAshraf
- File();
- int t = 1;
- // cin >> t;
- while (t--) {
- sol();
- }
- return 0;
- }
- void sol() {
- int n;
- cin>>n;
- vector<int>v(n);
- for(auto &it:v)cin>>it;
- sort(all(v));
- int m;
- cin>>m;
- auto valid=[&](int d)->bool{
- int cnt=0,last=-d;
- for(auto it:v){
- if(it-last>=d)cnt++,last=it;
- }
- return cnt>=m;
- };
- int ans=-1;
- int l=0,r=1e5,mid;
- while(l<=r){
- mid=l+(r-l)/2;
- if(valid(mid))ans=mid,l=mid+1;
- else r=mid-1;
- }
- cout<<ans;
- }
- void File() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
Add Comment
Please, Sign In to add comment