practivceAlgorithm/백준

[백준][Python] 19539 사과나무

findTheValue 2021. 8. 10. 19:27

아이디어는 결국 2와 1을 같은 횟수 사용해야 된다는 것. 

각 나무당 1을 필수적으로 써야할 횟수를 분리시킨다음 2를써야하는 횟수와 1을 써야하는 횟수의 차이(only 2만 있으면 해결 되는 수가 3의 배수고 2를써야하는 횟수가 더 많다면 2를 써야하는 횟수는 1과 2로 나눌 수 있으므로 가능하다. 

import sys
input = sys.stdin.readline

N = int(input())
h = list(map(int,input().split()))

two = 0
one = 0
for wood in h:
    two += wood//2
    one += wood%2

if not (two-one)%3 and two >= one:
    print('YES')
else:
    print('NO')