fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int main(){
  5. int n,t,i,q,j;
  6. scanf("%d",&t);
  7. for(i=0;i<t;i++){
  8. scanf("%d%d",&n,&q);
  9. int l[n],k[q];
  10. for(j=0;j<n;j++){
  11. scanf("%d",&l[j]);
  12. }
  13. sort(l,l+n);
  14. for(j=0;j<q;j++){
  15. scanf("%d",&k[j]);
  16. int* p= std::lower_bound(l,l+n,k[j]);
  17. int r=p-l-1,rcnt=p-l-1;
  18.  
  19. int x=r+1,cnt=0,el;
  20. while(x>0){
  21.  
  22. el=k[j]-l[r];
  23. x=x-1;
  24.  
  25. if(x>=el) cnt++;
  26. x=x-el;
  27. r--;
  28. }
  29. cout<<cnt<<endl;
  30. printf("%d\n",cnt+n-rcnt-1);
  31. }
  32.  
  33. }
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 15232KB
stdin
2
5 2
21 9 5 8 10
10
15
5 1
1 2 3 4 5
100
stdout
1
3
0
1
0
0