One day nn girls and nn boys come to Xi’an to look for a mate . Each girl has a value a[i] , each boy has a value b[i] . Girl i and boy j will fall in love only if a[i]+b[j]≥k .
Please help them make pairs as many as possible .
Input
Several test cases .
First line an integer T(1≤T≤10) . Indicates the number of test cases.
Then TT test cases follows . Each test case begins with two integer N, K(1≤N≤200000,0≤K≤109) . The next line has NN integers indicate a[1] to a[N](0≤a[i]≤109) . The next line has N integers indicate b[1] to b[N](0≤b[i]≤109)
Output
For each test case , print the answer in a single line.
样例输入复制
1 3 4 1 2 3 1 2 3
样例输出复制
3
思路:将两个数组都从大到小排序后,a数组从前往后找,b数组从后往前找,找到一个满足条件的b数组的j才变化。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int mod=1e9+7;
const int M=2e5 + 10;
ll a[M], b[M];
int main()
{
int t;
ll n, k;
scanf("%d", &t);
while(t--){
scanf("%lld%lld", &n, &k);
for (int i = 0; i < n; i++){
scanf("%lld", &a[i]);
}
for (int i = 0; i < n; i++){
scanf("%lld", &b[i]);
}
sort(a, a + n);
sort(b, b + n);
ll ans = 0;
int j = n - 1;
for (int i = 0; i < n; i++)
{
if(a[i]+b[j]>=k){
j--;
ans++;
}
}
printf("%lld\n", ans);
}
return 0;
}