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; }
相关文章推荐
- HackerRank "AND xor OR"
- HackerRank Between Two Sets
- HackerRank - "Team Formation"
- HackerRank "Kitty and Katty"
- HackerRank "Triangle Numbers"
- HackerRank "Arithmetic Expressions" !
- HackerRank "Chocolate in Box" !
- HackerRank - "Sam and sub"
- HackerRank - "Breadth First Search: Shortest Reach"
- HackerRank "Square Subsequences" !!!
- HackerRank "Equal Stacks"
- HackerRank "Angry Children 2"
- HackerRank "Richie Rich"
- HackerRank "Chessboard Game, Again!"
- HackerRank "Components in a graph"
- HackerRank "Bowling Pins" !!! [Game Theory]
- HackerRank "Array and simple queries" !
- HackerRank "Fair Rations"
- HackerRank - "String Modification"
- 【Hackerrank】Find the merge point of two joined linked lists