Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
#c
n,m,x=map(int, input().split())
sp = [list(map(int, input().split())) for _ in range(m)]

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost)

                for j in range(1,m+1):
                    i_sum[j-1] += sp[i-1][j]
                cost[0] +=  sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost)
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

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

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        print(i,i_sum,cost)
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])

                for j in range(1,m+1):
                    i_sum[j-1] += sp[i-1][j]
                cost[0] += sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

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

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        print(i,i_sum,cost)
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost)

                for j in range(1,m+1):
                    i_sum[j-1] += sp[i-1][j]
                cost[0] +=  sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost)
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

n,m,x = map(int, input().split())
c= []
a= []
ans = float('inf')
for i in range(n):
    c_tmp, *a_tmp = map(int, input().split())
    c.append(c_tmp)
    a.append(a_tmp)


cost_l =[]

for i in range(2 ** len(c)):
    cost = 0
    skill = [0]*m
    for j in range(len(c)):  
        if ((i >> j) & 1):
            cost += c[j]
            for k in range(m):
                skill[k] += int(a[j][k])
    
    f = 0
    for j in range(m):
        if skill[j] < x:
            f = 1
            break
    if f == 0:
        cost_l.append(cost)
            
if cost_l != []:
    print(min(cost_l))
else:
    print("-1")

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted