This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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, 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]]
new_amount = left_over[prev_subset] + bank[elem]
if new_amount == target_val:
ppl_satisfied[cur_subset] = ppl_satisfied[prev_subset] + 1
left_over[cur_subset] = 0
elif new_amount < target_val:
ppl_satisfied[cur_subset] = ppl_satisfied[prev_subset]
left_over[cur_subset] = new_amount
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... |