Editorial for Osman and an Array


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

If the sum of the given array is odd, the answer is not surprisingly "YES". But if it is not, we need to check how many odd elements and even elements there are. Because the sum is even and one way to change that is to assign an even number to an odd element or to assign an odd number to an even element. So if there is at least 1 even number and at least 1 odd number, the sum can be changed (if it is odd, it can be made even and vice versa).

#include <iostream>
#include <vector>

int main(){
    int i, j, t, n, odd, even, sum;
    std::vector<int> arr;
    std::cin >> t;
    for(i=0; i<t; i++){
        std::cin >> n;
        arr.resize(n, 0);
        for(j=0; j<n; j++) std::cin >> arr[j];
        odd=0; even=0; sum=0;
        for(j=0; j<n; j++){
            sum+=arr[j];
            if(arr[j]%2) odd++;
            else even++;
        }
        if(sum%2) std::cout << "YES\n";
        else if(odd && even) std::cout << "YES\n";
        else std::cout << "NO\n";
    }
}