fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16. #define yes cout << "yes\n"
  17. #define no cout << "no\n"
  18.  
  19. // Loops
  20. #define rep(i,a,b) for(int i=a;i<b;++i)
  21. #define per(i,a,b) for(int i=b-1;i>=a;--i)
  22. #define each(x, a) for (auto& x : a)
  23.  
  24. // Consts
  25. const int INF = 1e18;
  26. const int MOD = 1e9+7;
  27. const int N = 2e5 + 5;
  28.  
  29. // Logic
  30. void solve() {
  31. int n;
  32. int k;
  33. cin >> n >> k;
  34. vector<int> q(n);
  35. rep(i, 0, n) cin >> q[i];
  36. vector<int> r(n);
  37. rep(i, 0, n) cin >> r[i];
  38.  
  39. // Sort q descending: process hardest constraints first
  40. sort(all(q), greater<int>());
  41.  
  42. // Sort r ascending: incrementally add valid r's
  43. sort(all(r));
  44.  
  45. int r_ptr = 0;
  46. int ans = 0;
  47. vector<int> valid_r; // Acts as a stack
  48.  
  49. each(val_q, q) {
  50. // Condition: (val_q + 1) * (val_r + 1) <= k + 1
  51. // val_r <= (k + 1) / (val_q + 1) - 1
  52.  
  53. int limit = (k + 1) / (val_q + 1) - 1;
  54.  
  55. // Add all r's that satisfy the condition for the current (and subsequent) q
  56. while (r_ptr < n && r[r_ptr] <= limit) {
  57. valid_r.pb(r[r_ptr]);
  58. r_ptr++;
  59. }
  60.  
  61. // Match current q with an available r
  62. if (!valid_r.empty()) {
  63. valid_r.pop_back();
  64. ans++;
  65. }
  66. }
  67. cout << ans << endl;
  68. }
  69.  
  70. // Main
  71. int32_t main() {
  72. fast_io;
  73.  
  74. int t;
  75. cin >> t;
  76. while (t--) {
  77. solve();
  78. }
  79.  
  80. return 0;
  81. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
1 100
1
27
3 10
5 6 5
7 1 7
5 42
5 4 2 2 1
9 8 9 8 100
stdout
1
0
3