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):
#ABC167-C
import numpy as np
flg = True
n,m,x = map(int,input().split())
algo = []
tmp = []
for _ in range(n):
    algo.append(list(map(int,input().split())))
    
book = list(itertools.product([0,1],repeat=n))
abi = [0 for _ in range(m)]

for pattern in book:
    
    abi = [0 for _ in range(m)]
    money = 0
    flg = True
    
    for i in range(len(pattern)):
        for j in range(m):
            abi[j] += algo[i][j+1] * pattern[i]
        money += algo[i][0] * pattern[i]
        
    abi_min = [p for p in abi if p < x]
        
    if len(abi_min) != 0:
        flg = False
    if flg:
        print(money)
        tmp.append(money)

if len(tmp) > 0:
    print(min(tmp))
else:
    print(-1)
        
        
        
        
                
            

#C
import numpy as np
flg = True
n,m,x = map(int,input().split())
algo = []
for _ in range(n):
    algo.append(list(map(int,input().split())))
    

algo_n = np.array(algo)
algo_sum = algo_n.sum(axis=0)
gokei = algo_sum.tolist()
money = gokei[0]
gokei = gokei[1:]


for i in range(m):
    if gokei[i] < x:
        flg = False
        print(-1)
        break

algo.sort(key= lambda x:x[0],reverse=True)




def hikizan(lst1,lst2):
#lst1 - lst2
    for i in range(len(lst1)):
        l1 = lst1[i]
        l2 = lst2[i]
        l1 -= l2
        lst1[i] = l1
            
    return lst1

if flg:
    for i in range(n):
    flg = True
    for j in range(1,m+1):
        if gokei[j-1] - algo[i][j] < x:
            flg = False
            pass
    if flg:
        gokei = hikizan(gokei,algo[i][1:])
        money -= algo[i][0]
        
print(money)


        

#ABC167-C
import itertools
flg = True
n,m,x = map(int,input().split())
algo = []
tmp = []
for _ in range(n):
    algo.append(list(map(int,input().split())))
    
book = list(itertools.product([0,1],repeat=n))
abi = [0 for _ in range(m)]

for pattern in book:
    
    abi = [0 for _ in range(m)]
    money = 0
    flg = True
    
    for i in range(len(pattern)):
        for j in range(m):
            abi[j] += algo[i][j+1] * pattern[i]
        money += algo[i][0] * pattern[i]
        
    abi_min = [p for p in abi if p < x]
        
    if len(abi_min) != 0:
        flg = False
    if flg:
        print(money)
        tmp.append(money)

if len(tmp) > 0:
    print(min(tmp))
else:
    print(-1)
        
        
        
        
                
            

import itertools
n,m,x = map(int,input().split())
book = []
for _ in range(n):
    book.append(list(map(int,input().split())))

buy = list(itertools.product([0,1],repeat=n))

money = []

for i in range(len(buy)):
    algo = [0 for _ in range(m)]
    money_tmp = 0
    
    for j in range(len(buy[i])):
        for k in range(m):
            algo[k] += book[j][k+1] * buy[i][j]
        money_tmp += book[j][0]*buy[i][j]
    #print(money_tmp)
    if min(algo) >= x:
        money.append(money_tmp)
        
if len(money) > 0:    
    print(min(money))
else:
    print(-1)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted