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()
salaries = list(map(int, input().split()))
notes = list(map(int, input().split()))
if len(salaries) > len(notes):
print('NO')
exit()
combo_to_form = [[] for _ in range(len(salaries))]
for i, val in enumerate(salaries):
for subset in range(1 << len(notes)):
if sum(notes[j] for j in range(subset.bit_length()) if (1 << j) & subset) == val:
combo_to_form[i].append(subset)
if not combo_to_form[i]:
print('NO')
exit()
prev_subsets = {(1 << len(notes)) - 1}
for i in range(len(salaries)):
new_subsets = set()
for prev in prev_subsets:
for needed in combo_to_form[i]:
if (prev & needed) == needed:
new_subsets.add(prev - needed)
if not new_subsets:
print('NO')
exit()
prev_subsets = new_subsets
print('YES')
# | 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... |