Dazzling Even-Odd Challenge Solution || Codechef Starters - 37

        

Dazzling Even-Odd Challenge Solution 

Codechef Starters - 37
Problem Code : EANDO

Solution :

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll s = 0;
        ll even = 0, odd = 0;
        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
            s += a[i];
            if (a[i] % 2)
            {
                odd++;
            }
            else
            {
                even++;
            }
        }
        if (s % (n / 2) == 0)
        {
            ll temp = s / (n / 2);
            if (temp % 2 == 1)
            {
                cout << "YES\n";
            }
            else
            {
                cout << "NO\n";
            }
        }
        else
        {
            cout << "NO\n";
        }
    }
}

Comments