1807B - Grab the Candies - 800
On This Page
1807B - Grab the Candies (greedy, 800)
Explanation
- Read the number of bags and the list of candies in the bags.
- Calculate the total number of candies with even and odd amounts separately.
- Compare the total amount of candies with even and odd amounts.
- If Mihai has strictly more candies than Bianca, output “YES”. Otherwise, output “NO”.
Solution
t = int(input())
for _ in range(t):
n = int(input())
ar = list(map(int, input().split()))
m = 0
b = 0
if n == 1:
print('YES' if ar[0] % 2 == 0 else 'NO')
else:
for x in ar:
if x % 2 == 0:
m += x
else:
b += x
print('YES' if m > b else 'NO')