Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;
}
posted on 2015-05-27 00:44  Tonix  阅读(142)  评论(0)    收藏  举报