BOOKPAGES - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: notsoloud
Tester: yash_daga
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

There are N books, the i-th of them has A_i pages.
Is it possible to distribute these books to Alice and Bob such that both get at least one book, and both receive the same parity of pages?

EXPLANATION:

Notice that all the books must be distributed, and Alice and Bob receive the same parity of pages.
This means that the total number of pages across all books must be even.
After all, the sum of two odd numbers or the sum of two even numbers are both even.

It’s not hard to see that when the total sum is even, a valid distribution always exists.
In fact, you can distribute the books however you like: the parity condition will always be satisfied!

So, the answer is “Yes” if (A_1 + A_2 + \ldots + A_N) is even, and “No” otherwise.
This can be easily computed using a loop.

TIME COMPLEXITY

\mathcal{O}(N) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    print('Yes' if sum(a)%2 == 0 else 'No')