Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long arr[500010];
  4. bool check(long long value,long long x,long long l)
  5. {
  6.     if(x==1)return true;
  7.     long long sum=0;
  8.     for(long long i=l-1;i>=0;i--)
  9.     {
  10.         sum+=((arr[i])/value);
  11.     }
  12.     if(sum>=x)return true;
  13.     else return false;
  14. }
  15. void bs(long long l,long long key)
  16. {
  17.     long long low=1;
  18.     long long high=arr[l-1]+1;
  19.     long long mid=0;
  20.     while(low<high)
  21.     {
  22.         mid=(low+high)/2;
  23.         if(check(mid,key,l))low=mid+1;
  24.         else high=mid-1;
  25.     }
  26.     cout<<low-1<<endl;
  27. }
  28. int main()
  29. {
  30.     long long t;
  31.     cin>>t;
  32.     while(t--)
  33.     {
  34.         long long n,k;
  35.         cin>>n>>k;
  36.         for(long long i=0;i<n;i++)
  37.         {
  38.             cin>>arr[i];
  39.         }
  40.         sort(arr,arr+n);
  41.         bs(n,k);
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement