Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define pb push_back
- #define fi first
- #define se second
- #define in insert
- #define mp make_pair
- #define GCD(a,b) __gcd(a,b);
- #define endl "\n"
- #define FRU freopen("out.txt","w",stdout)
- #define FRO freopen("in.txt","r",stdin)
- #define INFLL 9223372036854775807
- //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
- ll a[100001];
- bool istrue(ll mid,ll n,ll c)
- {
- ll cnt=0,i,pref=-INT_MAX;
- for(i=1;i<=n;i++)
- {
- if(a[i]-pref>=mid)
- {
- cnt++;
- pref=a[i];
- }
- }
- if(cnt>=c)
- return true;
- else
- return false;
- }
- ll bs(ll n,ll c)
- {
- ll l=0,h=a[n]-a[1],mid,ans=0;
- while(l<h)
- {
- mid=(l+h)/2 ;
- if(istrue(mid,n,c))
- ans=max(ans,mid),l=mid+1;
- else
- h=mid-1;
- }
- return ans;
- }
- int main()
- {
- fastio;
- ll t;
- cin>>t;
- while(t--)
- {
- ll n,c,i;
- cin>>n>>c;
- for(i=1;i<=n;i++)
- {
- cin>>a[i];
- }
- sort(a+1,a+n+1);
- cout<<bs(n,c)<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement