CodeForces-1296 A Array with Odd Sum

See this article on my own blog https://dyingdown.github.io/2020/02/05/CodeForces-1296A-Array-with-Odd-Sum/

A. Array with Odd Sum
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output:standard output

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 1i,jn 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) (1t2000) — 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) (1n2000) — 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) (1ai2000), where a i ai ai is the i − t h i-th ith 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) (n2000).

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值