您的位置:首页 > 其它

HackerRank - "Two arrays"

2015-05-27 00:44 316 查看
We match larger in array_a with smaller in array_b, by which we can have as even sum as possible, so we don't have too small sums.

#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

int main()
{
int t; cin >> t;
while (t--)
{
int n, k; cin >> n >> k;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];

sort(a.begin(), a.end());
sort(b.begin(), b.end(), std::greater<int>());

bool bBad = false;
for (int i = 0; i < n; i++)
{
if ((a[i] + b[i]) < k)
{
bBad = true;
break;
}
}
cout << (bBad?"NO":"YES") << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: