Problem p02683 (python)

Fixed submission:
import numpy as np

n,m,x = [int(i) for i in input().split()]
costs =[]
maa = 1000000000000000000000000000
ans = maa

for i in range(n):
    a = [int(i) for i in input().split()]
    costs.append(a)
    
for i in range(1,2**n+1):
    cost = 0
    c = 0
    sums = [0] * m
    use_index=[]
    for j in range(n):
        if i%2==1:
            use_index.append(j)
        i >>= 1
    
    for v in use_index:
        c += costs[v][0]        
        for j in range(m):
            sums[j] += costs[v][j+1]
            
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)

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

Buggy submission (verdict: Runtime Error):
#abc_167_c
#itertools.productを使うバージョン

from itertools import product

n,m,x = map(int, input().split())
costs = [list(map(int, input().split())) for _ in range(n)]

INF = 1000000000000000000000000000
ans = INF


lists = list(product(list(range(2)), repeat = n))
for v in lists:
'''
for i in range(1<<n):  #n bits all searches
    # 1<<n == 2**n
'''
    c = 0
    sums = [0]*m
    for j in range(n):
        if v[j]==1:        
        '''
        if i>>j & 1: #i>>j %2 == 1  is also fine.
        '''
            #apply this candidate. 
            c += costs[j][0]
            for k in range(m):
                sums[k] += costs[j][k+1]    
                
                
    if min(sums) >= x: #if all(s>=x for s in sums) でもよい
        ans = min(ans, c)                
    '''
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)
    でもよい。
    '''
    
        
if ans==INF:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n,m,x = map(int, input().split())
costs = [list(map(int, input().split())) for _ in range(n)]

'''
n,m,x = [int(i) for i in input().split()]
costs =[]

for i in range(n):
    a = [int(i) for i in input().split()]
    costs.append(a)
'''


INF = 1000000000000000000000000000
ans = INF

for i in range(1<<n):  #n bits all searches
    # 1<<n == 2**n
    c = 0
    sums = [0]*m
    for j in range(n):
        if i>>j & 1: #i>>j %2 == 1  is also fine.
            #apply this candidate. 
            c += costs[j][0]
            for k in range(m):
                sums[k] += costs[j][k+1]    
    '''
    cost = 0
    c = 0
    sums = [0] * m
    use_index=[]
    for j in range(n):
        if i%2==1:
            use_index.append(j)
        i >>= 1
    
    for v in use_index:
        c += costs[v][0]        
        for j in range(m):
            sums[j] += costs[v][j+1]
    '''
    
    #if min(sums) >= x:
    if all(s>=x for x in sums):
        ans = min(ans, c)
'''            
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)
'''
if ans==INF:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n,m,x = map(int, input().split())
costs = [list(map(int, input().split())) for _ in range(n)]

'''
n,m,x = [int(i) for i in input().split()]
costs =[]

for i in range(n):
    a = [int(i) for i in input().split()]
    costs.append(a)
'''


INF = 1000000000000000000000000000
ans = INF

for i in range(1<<n):  #n bits all searches
    # 1<<n == 2**n
    c = 0
    sums = [0]*m
    for j in range(n):
        if i>>j & 1: #i>>j %2 == 1  is also fine.
            #apply this candidate. 
            c += costs[j][0]
            for k in range(m):
                sums[k] += costs[j][k+1]
    
'''
    cost = 0
    c = 0
    sums = [0] * m
    use_index=[]
    for j in range(n):
        if i%2==1:
            use_index.append(j)
        i >>= 1
    
    for v in use_index:
        c += costs[v][0]        
        for j in range(m):
            sums[j] += costs[v][j+1]
'''

    if min(sums) >= x:
        ans = min(ans, c)

'''            
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)
'''
ans = -1 if ans==INF 
print(ans)