zoukankan      html  css  js  c++  java
  • HackerRank

    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;
    }
  • 相关阅读:
    四种nlogn排序算法代码
    HDU1421
    HDU1789
    HDU1978
    HDU2059
    HDU2089
    深入理解数组与指针的区别
    存储字节对齐问题
    h5新特性<data*>
    浏览器的标准模式和怪异模式
  • 原文地址:https://www.cnblogs.com/tonix/p/4532204.html
Copyright © 2011-2022 走看看