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):
import numpy as np  
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  
    I[i] = val2

seq = [i for i in range(val[0])]  
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    # print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

# print(ans)
if(len(ans) == 0):
    print('-1')
else:
    print(min(ans))

import numpy as np  
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  
    I[i] = val2

seq = [i for i in range(val[0])]  
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

# print(ans)
if(len(ans) == 0):
    print('-1')
else:
    print(int(min(ans)))

import numpy as np  
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  
    I[i] = val2

seq = [i for i in range(val[0])]  
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

# print(ans)
if(len(ans) == 0):
    print('-1')
else:
    print(min(ans))


import numpy as np  
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  
    I[i] = val2

seq = [i for i in range(val[0])]  
print(seq)

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    # print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        print(I_sum)
        ans = [sum(i) for m in I_sum]
        print('ans=', ans)
        
        #     print(I[Com_list])


import numpy as np  
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  
    I[i] = val2

seq = [i for i in range(val[0])]  
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    # print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

# print(ans)
if(len(ans) == 0):
    print('-1')
else:
    print(int(min(ans)))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted