Submission #1089476

#TimeUsernameProblemLanguageResultExecution timeMemory
1089476vjudge1Bank (IZhO14_bank)Cpython 3
52 / 100
1074 ms19268 KiB
import array

n, m = map(int, input().split())

valores = array.array('i', map(int, input().split()))
notas = array.array('i', map(int, input().split()))

residual = array.array('i', [-1] * (1 << m))
cobertos = array.array('i', [-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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...