#K7296. Odd Subset Sum
Odd Subset Sum
Odd Subset Sum
You are given an array of n positive integers and an integer k. Your task is to determine whether there exists a subset of exactly k elements such that the sum of the subset is odd.
A sum is odd if and only if the number of odd elements in the chosen subset is odd. In other words, if you select x odd numbers and k-x even numbers, then the sum is odd if and only if x is odd. Formally, you need to check if there exists an odd number x satisfying \[ 1 \le x \le \min(k, O) \quad\text{and}\quad k - x \le E, \] where O is the number of odd numbers in the array and E is the number of even numbers in the array.
Output YES if such a subset exists; otherwise, output NO.
inputFormat
The input is read from standard input (stdin) and has the following format:
T n1 k1 a1,1 a1,2 ... a1,n1 n2 k2 a2,1 a2,2 ... a2,n2 ... nT kT aT,1 aT,2 ... aT,nT
Here, the first line contains the number of test cases T. For each test case, the first line contains two integers: n (the size of the array) and k (the required number of elements to choose). The second line contains n positive integers denoting the array elements.
outputFormat
For each test case, print a single line with the answer: YES if there exists a subset of exactly k elements whose sum is odd, and NO otherwise. The output should be written to standard output (stdout).
## sample2
5 3
1 2 3 4 5
4 2
2 4 6 8
YES
NO
</p>