This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
from collections import Counter
def subset_sum(nums_count, target):
dp = {0: []}
for num, count in nums_count.items():
for _ in range(count):
new_sums = {}
for partial_sum, subset in dp.items():
new_sum = partial_sum + num
if new_sum == target:
return subset + [num]
if new_sum < target:
new_sums[new_sum] = subset + [num]
dp.update(new_sums)
return None
def remove_subset_values(nums_count, subset):
for value in subset:
if nums_count[value] > 0:
nums_count[value] -= 1
n, m = map(int, input().split())
valores = list(map(int, input().split()))
notas = list(map(int, input().split()))
notas_count = Counter(notas)
possivel = 1
for v in valores:
solution = subset_sum(notas_count, v)
if solution is None:
possivel = 0
break
else:
remove_subset_values(notas_count, solution)
if possivel == 1:
print("YES")
else:
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... |