This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
n, m = [int(x) for x in input().split()]
valores = [int(x) for x in input().split()]
notas = [int(x) for x in input().split()]
residual = [-1] * (1 << m)
cobertos = [-1] * (1 << m)
residual[0] = 0
cobertos[0] = 0
possivel = 1
for s in range(1 << m):
for p in range(m):
if (s & (1 << p)) == 0:
continue
ant = s & ~(1 << p)
if cobertos[ant] == -1:
continue
novo = residual[ant] + notas[p]
if cobertos[ant] < n:
alvo = valores[cobertos[ant]]
else:
continue
if novo < alvo:
cobertos[s] = cobertos[ant]
residual[s] = novo
elif novo == alvo:
cobertos[s] = cobertos[ant] + 1
residual[s] = 0
if cobertos[s] == n:
possivel = 0
if possivel == 0:
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... |