See this article on my own blog https://dyingdown.github.io/2020/02/05/CodeForces-1296A-Array-with-Odd-Sum/
You are given an array a a a consisting of n n n integers.
In one move, you can choose two indices 1 ≤ i , j ≤ n 1≤i,j≤n 1≤i,j≤n such that i ≠ j i≠j i=j and set a i : = a j ai:=aj ai:=aj . You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment ( i . e . i.e. i.e. you choose i i i and j j j and replace a i ai ai with a j aj aj).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t t t independent test cases.
Input
The first line of the input contains one integer t t t ( 1 ≤ t ≤ 2000 ) (1≤t≤2000) (1≤t≤2000) — the number of test cases.
The next 2 t 2t 2t lines describe test cases. The first line of the test case contains one integer n n n ( 1 ≤ n ≤ 2000 ) (1≤n≤2000) (1≤n≤2000) — the number of elements in a a a. The second line of the test case contains n n n integers a 1 , a 2 , … , a n a1,a2,…,an a1,a2,…,an ( 1 ≤ a i ≤ 2000 ) (1≤ai≤2000) (1≤ai≤2000), where a i ai ai is the i − t h i-th i−th element of a a a.
It is guaranteed that the sum of n n n over all test cases does not exceed 2000 2000 2000 ( ∑ n ≤ 2000 ) (∑n≤2000) (∑n≤2000).
Output
For each test case, print the answer on it — “YES” (without quotes) if it is possible to obtain the array with an odd sum of elements, and “NO” otherwise.
Example
input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
output
YES
NO
YES
NO
NO
Analysis
If there is no odd number, then no matter how to move it will stay all even, so it’s NO.
If there is odd number and even number, then it can be YES because it can make the number of odds an odd number.
If there is only odd number, checkout for the total number n, if n is a odd number, then it’s YES; If n is an even number, then it’s NO.
Code
#include<bits/stdc++.h>
using namespace std;
int a[200000];
int main() {
int t;
cin >> t;
while(t --) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1) odd++;
else even++;
}
if (odd == 0 or (even == 0 and n % 2 == 0)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}