이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
input()
people = list(map(int, input().split()))
bank = list(map(int, input().split()))
ppl_satisfied = [0] * (1 << len(bank))
left_over = [0] * (1 << len(bank))
for cur_subset in range(1 << len(bank)):
for elem in range(len(bank)):
if cur_subset & (1 << elem):
prev_subset = cur_subset ^ (1 << elem)
target_val = people[ppl_satisfied[prev_subset]]
if left_over[prev_subset] + bank[elem] == target_val:
ppl_satisfied[cur_subset] = ppl_satisfied[prev_subset] + 1
left_over[cur_subset] = 0
else:
ppl_satisfied[cur_subset] = ppl_satisfied[prev_subset]
left_over[cur_subset] = left_over[prev_subset] + bank[elem]
if ppl_satisfied[cur_subset] == len(people):
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... |