Buggy python submission (verdict: Time Limit Exceeded):
# encoding: utf-8


import sys

__input = sys.stdin.readlines()
length_1 = int(__input[0])
array_1 = list(map(int, __input[1].split()))
length_2 = int(__input[2])
array_2 = list(map(int, __input[3].split()))


def solution():
    # print(length_1, array_1, length_2, array_2)
    assert length_1 == len(array_1) and length_2 == len(array_2)

    for i in range(length_2):
        ans = solve(0, array_2[i])
        if ans:
            print("yes")
        else:
            print("no")
    return None


def solve(i, m):
    if m == 0:
        return True
    if i >= length_1:
        return False
    res = solve(i + 1, m) or solve(i + 1, m - array_1[i])
    return res


if __name__ == '__main__':
    solution()

Fixed submission:
# encoding: utf-8


import sys

__input = sys.stdin.readlines()
length_1 = int(__input[0])
array_1 = list(map(int, __input[1].split()))
length_2 = int(__input[2])
array_2 = list(map(int, __input[3].split()))

record = [False] * 2000


def solution():
    # print(length_1, array_1, length_2, array_2)
    assert length_1 == len(array_1) and length_2 == len(array_2)

    for i in array_1:
        # record[i] = True
        for j in range(2000 - i, 0, -1):
            if record[j]:
                # print(j, i + j)
                record[i + j] = True
        record[i] = True

    for index in array_2:
        if record[index]:
            print("yes")
        else:
            print("no")


if __name__ == '__main__':
    solution()

Buggy python submission (verdict: Time Limit Exceeded):
# encoding: utf-8


import sys

__input = sys.stdin.readlines()
length_1 = int(__input[0])
array_1 = list(map(int, __input[1].split()))
length_2 = int(__input[2])
array_2 = list(map(int, __input[3].split()))
upperbound = 2000
assert length_1 == len(array_1) and length_2 == len(array_2)


def solution_1():
    record = [False] * upperbound

    for i in array_1:
        # record combinations of sums of each in array_1
        for j in range(upperbound - i, 0, -1):
            if record[j]:
                record[int(i + j)] = True
        record[i] = True

    for each in array_2:
        if record[each]:
            print("yes")
        else:
            print("no")


def solution_2():
    for each in array_2:
        # print('e', each)
        ans = solve(0, each)
        if ans:
            print("yes")
        else:
            print("no")


def solve(i, m):
    if m == 0:
        # print('c')
        return True
    if i >= length_1:
        # print('a', i, m)
        return False

    # print('b', i, m)
    ans = solve(i + 1, m) or solve(i + 1, m - array_1[i])
    return ans


if __name__ == '__main__':
    # solution_1()
    solution_2()

Fixed submission:
# encoding: utf-8


import sys

__input = sys.stdin.readlines()
length_1 = int(__input[0])
array_1 = list(map(int, __input[1].split()))
length_2 = int(__input[2])
array_2 = list(map(int, __input[3].split()))

record = [False] * 2000


def solution():
    # print(length_1, array_1, length_2, array_2)
    assert length_1 == len(array_1) and length_2 == len(array_2)

    for i in array_1:
        # record[i] = True
        for j in range(2000 - i, 0, -1):
            if record[j]:
                # print(j, i + j)
                record[i + j] = True
        record[i] = True

    for index in array_2:
        if record[index]:
            print("yes")
        else:
            print("no")


if __name__ == '__main__':
    solution()