#C1801. Exactly K Element Selection
Exactly K Element Selection
Exactly K Element Selection
You are given two sequences A and B, each containing n integers. Your task is to determine whether it is possible to select exactly k elements from sequence A and exactly k elements from sequence B such that the sum of the selected elements from A is less than or equal to the sum of the selected elements from B.
In other words, if we denote the selected elements from A as \(a_1, a_2, \dots, a_k\) and from B as \(b_1, b_2, \dots, b_k\), you need to check if:
[ \sum_{i=1}^{k} a_i \leq \sum_{i=1}^{k} b_i ]
Hint: The optimal strategy is to choose the k smallest elements from A and the k largest elements from B.
inputFormat
The input is read from stdin and has the following format:
- The first line contains a single integer T denoting the number of test cases.
- For each test case:
- The first line contains two integers n and k.
- The second line contains n space-separated integers representing sequence A.
- The third line contains n space-separated integers representing sequence B.
outputFormat
For each test case, print a single line to stdout with the answer: "YES" if it is possible to select the elements such that the sum condition is satisfied, and "NO" otherwise.
## sample5
5 3
1 2 3 4 5
5 4 3 2 1
5 2
1 1 1 1 10
2 2 2 2 1
5 2
1 1 1 1 10
2 2 2 2 11
3 1
3 3 3
1 1 1
4 2
2 2 2 2
1 1 3 3
YES
YES
YES
NO
YES
</p>