1807B - Grab the Candies - 800

Updated: 2024-03-12
1 min read

1807B - Grab the Candies (greedy, 800)

Explanation

  1. Read the number of bags and the list of candies in the bags.
  2. Calculate the total number of candies with even and odd amounts separately.
  3. Compare the total amount of candies with even and odd amounts.
  4. 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')