Problem p02683 (python)

Fixed submission:
n, m, x = map(int, input().split())
c = [0] * n
for i in range(n):
    c[i] = [int(_) for _ in input().split()]

ans = 10**10
for i in range(2 ** n):
    state = [0] * n
    for j in range(n):
        state[j] = (i >> j) & 1
    #print(state)
    num = [0] * m
    val = 0

    for j in range(n):
        if state[j] == 1:
            for k in range(m):
                num[k] += c[j][k+1]
            val += c[j][0]

    flag = True
    for j in range(m):
        if num[j] < x:
            flag = False
            break
    if flag:
        ans = min(ans, val)

if ans == 10**10:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    inp = [int(_) for _ in input().split()]
    c[i] = inp[0]
    a[i] = inp[1:]

#print(c)
#print(a)

ans = 10**10
pat = list(product([0, 1], repeat=n))

for p in pat:
    a_val = [0] * n
    c_yen = 0

    for i in range(n):
        if p[i] == 1:
            c_yen += c[i]
            for j in range(m):
                a_val[j] += a[i][j]

    flag = True
    for i in range(m):
        if a_val[i] < x:
            flag = False
            break
    if flag:
        ans = min(ans, c_yen)

if ans == 10**10:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    inp = [int(_) for _ in input().split()]
    c[i] = inp[0]
    a[i] = inp[1:]

INIT = 10**10
ans = INIT
#pat = list(product([0, 1], repeat=n))

for p in range(2**n):
    state = [0] * n
    for j in range(n):
        state[j] = (p >> j) & 1

    a_val = [0] * n
    c_yen = 0

    for i in range(n):
        if state[i] == 1:
            c_yen += c[i]
            for j in range(m):
                a_val[j] += a[i][j]

    flag = True
    for i in range(m):
        if a_val[i] < x:
            flag = False
            break
    if flag:
        ans = min(ans, c_yen)

if ans == INIT:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    c[i] = [int(_) for _ in input().split()]

INIT = 10**10
ans = INIT
pat = list(product([0, 1], repeat=n))

for p in pat:
    a_val = [0] * n
    c_yen = 0

    for i in range(n):
        if p[i] == 1:
            c_yen += c[i][0]
            for j in range(m):
                a_val[j] += c[i][j+1]

    flag = True
    for i in range(m):
        if a_val[i] < x:
            flag = False
            break
    if flag:
        ans = min(ans, c_yen)

if ans == INIT:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    c[i] = [int(_) for _ in input().split()]

INIT = 10**10
ans = INIT
pat = list(product([0, 1], repeat=n))

for p in pat:
    a_val = [0] * n
    c_yen = 0

    for i in range(n):
        if p[i] == 1:
            c_yen += c[i][0]
            for j in range(m):
                a_val[j] += c[i][j+1]

    flag = True
    for i in range(m):
        if a_val[i] < x:
            flag = False
            break
    if flag:
        ans = min(ans, c_yen)

if ans == INIT:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    inp = [int(_) for _ in input().split()]
    c[i] = inp[0]
    a[i] = inp[1:]

INIT = 10**10
ans = INIT
pat = list(product([0, 1], repeat=n))

for p in pat:
    a_val = [0] * n
    c_yen = 0

    for i in range(n):
        if p[i] == 1:
            c_yen += c[i]
            for j in range(m):
                a_val[j] += a[i][j]

    flag = True
    for i in range(m):
        if a_val[i] < x:
            flag = False
            break
    if flag:
        ans = min(ans, c_yen)

if ans == INIT:
    print(-1)
else:
    print(ans)