Problem p02683 (python)

Fixed submission:
import itertools

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

ans = []

for s in itertools.product(range(2), repeat=N):

    li = [0 for _ in range(M)]
    cum = 0
    for i, v in enumerate(s):
        if v == 1:
            ca = CA[i]
            cum += ca[0]

            for j, x in enumerate(ca[1:]):
                li[j] += x

        q = [p >= X for p in li]
        if all(q):
            ans.append(cum)

print(min(ans) if ans else -1)

Buggy submission (verdict: Runtime Error):
import copy
from collections import Counter

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

cc = 0
MM = 0
for ca in CA:
    cc += ca[0]

    if MM < max(ca[1:]):
        MM = max(ca[1:])

U = 10**5 * cc + 1

dp = []
for i in range(M):
    p_dp = [U for _ in range(MM * M + 1)]
    p_dp[0] = 0
    dp.append(p_dp)

for ca in CA:
    c = ca[0]
    a = ca[1:]

    for i, v in enumerate(a):
        p_dp = copy.deepcopy(dp)
        for j in range(MM * M + 1 - v):
            if dp[i][j] < U:
                dp[i][j + v] = min(p_dp[i][j + v], p_dp[i][j] + c)

ans_list = list(set(dp[0][X:]))

for i in range(1, M):
    ans_list = list(set(ans_list) & set(dp[i][X:]))

print(min(ans_list) if min(ans_list) < U else -1)

Buggy submission (verdict: Runtime Error):
import copy
from collections import Counter

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

cc = 0
MM = 0
for ca in CA:
    cc += ca[0]

    if MM < max(ca[1:]):
        MM = max(ca[1:])

U = 10**5 * cc + 1

dp = []
for i in range(M):
    p_dp = [U for _ in range(MM * M + 1)]
    p_dp[0] = 0
    dp.append(p_dp)

for ca in CA:
    c = ca[0]
    a = ca[1:]

    for i, v in enumerate(a):
        p_dp = copy.deepcopy(dp)
        for j in range(MM * M + 1 - v):
            if dp[i][j] < U:
                dp[i][j + v] = min(p_dp[i][j + v], p_dp[i][j] + c)

ans_list = list(set(dp[0][X:]))

for i in range(1, M):
    ans_list = list(set(ans_list) & set(dp[i][X:]))

print(min(ans_list) if min(ans_list) < U else -1)

Buggy submission (verdict: Runtime Error):
import copy
from collections import Counter

import numpy as np

N, M, X = map(int, input().split())
CA = np.array([list(map(int, input().split())) for _ in range(N)])

cc = np.sum(CA[:, 0])
U = 10**5 * cc +1

dp = np.full([M, 10**5 * M + 1], U, dtype=np.int32)
dp[:, 0] = 0

for ca in CA:
    c = ca[0]
    a = ca[1:]

    for i, v in enumerate(a):
        p_dp = copy.deepcopy(dp)
        np.minimum(dp[i, v:], p_dp[i, :-v] + c, out=dp[i, v:])

p_ans = dp[:, X:]

ans_list = []
for i in range(M):
    ans_list += list(set(p_ans[i]))

C = sorted(Counter(ans_list).items())

for k, v in C:
    if v >= M:
        if k >= U:
            print(-1)
            break
        else:
            print(k)
            break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import copy

from collections import Counter

import numpy as np

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

dp = np.full([M, 2 * 10**5 + 1], 10**5, dtype=np.int32)
dp[:, 0] = 0

for ca in CA:
    c = ca[0]
    a = ca[1:]

    for i, v in enumerate(a):
        p_dp = copy.deepcopy(dp)
        np.minimum(dp[i, v:], p_dp[i, :-v] + c, out=dp[i, v:])

p_ans = dp[:, X:]

ans_list = []
for i in range(M):
    ans_list += list(set(p_ans[i]))

C = sorted(Counter(ans_list).items())

for k, v in C:
    if v >= M:
        if k == 10**5:
            print(-1)
            break
        else:
            print(k)
            break
else:
    print(-1)