#C1606. Even Array Transformation
Even Array Transformation
Even Array Transformation
Chef is given an array B of M integers. Chef can perform the following operation any number of times: select exactly X indices and increment each of the elements at these indices by 1. The goal is to transform the array such that all its elements become even.
Let \(odd\_count\) denote the number of odd elements in the array. Chef can achieve the goal if either:
- \(odd\_count = 0\); that is, the array is already even, or
- \(odd\_count \equiv 0 \pmod{X}\); this is because, in each valid operation, Chef can flip the parity of exactly X numbers.
Formally, Chef can transform the array if and only if \[ \text{possible} \iff (odd\_count = 0) \quad \text{or} \quad (odd\_count \equiv 0 \pmod{X}). \]
inputFormat
The input begins with an integer T denoting the number of test cases. Each test case has two parts:
- The first line contains two integers M and X, where M is the size of the array and X is the exact number of indices to select in an operation.
- The second line contains M space-separated integers representing the array B.
outputFormat
For each test case, output a single line containing "YES" if it is possible to make all elements even using the allowed operations, otherwise output "NO".
## sample4
5 3
1 3 5 2 4
6 2
3 5 7 9 10 12
5 1
4 7 8 10 2
4 4
2 4 6 8
YES
YES
YES
YES
</p>