fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll binarysearch(vector<ll> v,ll low, ll high, ll k)
  5. {
  6.  
  7. ll mid= low +(high-low)/2;
  8. if(low==high)
  9. return high;
  10. if(high-low==1)
  11. return k>v[low]?high:low;
  12. if(v[mid]==k)
  13. return mid;
  14. else if(v[mid]>k)
  15. return binarysearch(v,low,mid,k);
  16. else
  17. return binarysearch(v,mid+1,high,k);
  18. }
  19. int main() {
  20. // your code goes here
  21. ll t;
  22. cin>>t;
  23. while(t--)
  24. {
  25. ll n,q;
  26. cin>>n>>q;
  27. vector<ll> v(n,0);
  28. for(ll i=0;i<n;i++)
  29. cin>>v[i];
  30. sort(v.begin(),v.end());
  31. ll k;
  32. while(q--)
  33. {
  34. cin>>k;
  35. ll in=binarysearch(v,0,n-1,k);
  36. if(v[in]<k)
  37. cout<<"0"<<endl;
  38. else{
  39. ll no=(n)-in;
  40. ll start=in-1, end=0;
  41. while(start>end)
  42. {
  43. ll req=k-v[start];
  44. if(end+req<in)
  45. {
  46. no++;
  47. end=end+req;
  48. }
  49.  
  50. start--;
  51. }
  52. cout<<no<<endl;
  53. }
  54.  
  55. }
  56.  
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0s 16056KB
stdin
2
5 2
21 9 5 8 10
10
15
5 1
1 2 3 4 5
100
stdout
3
1
0