问题描述
花朵并非仅绽放于天地,在天外之处亦可大展光彩
这句话完全就是我的写照
尽管怀抱敬畏之心,翘首仰望我吧
我正是天外之花――爱莲娜·古罗利亚!
爱莲娜拥有一个力量强大的术式,名为「天外的一隅」
爱莲娜还拥有两个序列 {ai} 和 {bi},以及一个充能序列 {si},其中 si=ai+bi,当充能序列中任意一个位置的能量超过 x,该术式将启动
爱莲娜为了不让术式启动,会将序列 {ai} 和 {bi} 进行任意重新排序
现在爱莲娜想问你,她在重新排列两个序列以后,能否阻止术式启动,能输出YES,不能输出NO
输入格式
第一行一个整数 T ,表示输入数据的组数
接下来每组数据中,第一行两个整数 n,x,第二行 n 个整数 ai,第三行 n 个整数 bi
输出格式
共 T 行,每行输出一个整数表示答案
样例
输入
4
3 4
1 2 3
1 1 2
2 6
1 4
2 5
4 4
1 2 3 4
1 2 3 4
1 5
5
5
输出
YES
YES
NO
NO
数据范围
数据保证 1≤T≤100,1≤x,∑n≤105,1≤ai,bi≤x
解决方案
思路
排序
代码
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
int n, x;
static int a[N];
static int b[N];
cin >> n >> x;
for (int j = 0; j < n; ++j) {
cin >> a[j];
}
for (int j = 0; j < n; ++j) {
cin >> b[j];
}
int res = true;
sort(a, a + n);
sort(b, b + n, greater<int>());
for (int j = 0; j < n; ++j) {
if (a[j] + b[j] > x) {
res = false;
}
}
if (res)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}