이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
from sys import exit
people_num, note_num = [int(i) for i in input().split()]
people = [int(i) for i in input().split()]
banknotes = [int(i) for i in input().split()]
leftover = [-1 for _ in range(1 << note_num)]
people_covered = [-1 for _ in range(1 << note_num)]
for s in range(1, 1 << note_num):
for last in range(people_num):
if (s & (1 << last)) == 0:
continue
prev = s & ~(1 <<last)
if people_covered[prev] == -1:
continue
new_amt = leftover[prev] + banknotes[last]
curr_target = people[people_covered[prev]]
if new_amt < curr_target:
people_covered[s] = people_covered[prev]
leftover[s] = new_amt
elif new_amt == curr_target:
people_covered[s] = people_covered[prev] + 1
leftover[s] = 0
if people_covered[s] == people_num:
print("YES")
exit()
print("NO")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |