Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef int l;
- typedef long long int ll;
- #define loop(a, b) for(int i = a; i < b; i++)
- void run(){
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output7.txt", "w", stdout);
- #else
- #endif
- }
- bool check(ll ara[], l n, l m, ll mid){
- m--;
- l current = 0;
- l j = 1;
- while(j < n){
- if(abs(ara[current] - ara[j]) >= mid){
- current = j;
- m--;
- }
- if(m <= 0) return true;
- j++;
- }
- return false;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- //run();
- l t;cin>>t;
- while(t--){
- l n, m;cin>>n>>m;
- ll ara[n];loop(0, n) cin>>ara[i];
- sort(ara, ara+n);
- ll left = 2, right = abs(ara[n-1] - ara[0]);
- while(left <= right){
- l mid = left + ((right - left) >> 1);
- if(check(ara, n, m, mid)) left = mid + 1;
- else right = mid - 1;
- }
- cout << right << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement