Problem:
 Score : 300 points    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.      Constraints  All values in input are integers.  1\leq N, M\leq 12  1\leq X\leq 10^5  1\leq C_i \leq 10^5  0\leq A_{i, j} \leq 10^5         Input Input is given from Standard Input in the following format:  N  M  X  C_1  A_{1,1}  A_{1,2}  \cdots  A_{1,M}  C_2  A_{2,1}  A_{2,2}  \cdots  A_{2,M}  \vdots  C_N  A_{N,1}  A_{N,2}  \cdots  A_{N,M}       Output If the objective is not achievable, print -1 ; otherwise, print the minimum amount of money needed to achieve it.        Sample Input 1 3 3 10
60 2 2 4
70 8 7 9
50 2 3 9      Sample Output 1 120  Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.       Sample Input 2 3 3 10
100 3 1 4
100 1 5 9
100 2 6 5      Sample Output 2 -1  Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.       Sample Input 3 8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2      Sample Output 3 1067

Solution (Python):
def function():
    N,M,X = map(int, input().split())
    maxCost=0
    Aij = []
    for n in range(0,N):
        Aj = list(map(int, input().split()))
        maxCost += Aj[0]
        Aij.append(Aj)

    maxCost += 1
    minCost = maxCost
    total = pow(2, N)
    for n in range(1,total):
        x = [0]*M
        cost = 0
        i = 0
        while n>>i != 0:
            if (n>>i) & 1 == 1:
                Aj = Aij[i]
                cost += Aj[0]
                for j in range(1,len(Aj)):
                    x[j-1] += Aj[j]
            i += 1
        
        
        higher = True
        for xv in x:
            if xv < X:
                higher = False
                break
        if higher == True:
            minCost = min(cost, minCost)
    if minCost == maxCost:
        minCost = -1
    print(minCost)

if __name__ == '__main__':
    function()

Solution (Python):

from itertools import combinations
from itertools import product
import numpy as np 
import sys
input   = sys.stdin.readline
N,M,X   = (int(x) for x in input().split())
C       = [list(map(int, input().split())) for i in range(N)]
all_book= [i for i in range(N)]          

price_list  =[]
flag        =False
C_np        =np.array(C,dtype=int)
price       =C_np[:,0]
understand  =np.delete(C_np,0,1)

for num in range(1,N+1): 
    for t in combinations(all_book,num): 
        book_buy         =np.array(t,dtype=int)      
        understand_now   =understand[book_buy]       
        understand_sum   =np.sum(understand_now,axis=0) 

        if np.all(X <= understand_sum ): 
            price_now =price[book_buy]
            price_list.append(np.sum(price_now))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Solution (Python):
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        
N, M, X = map(int, input().split())
C_np    = np.array([list(map(int, input().split())) for _ in range(N)], dtype=int)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]

price       =C_np[:,0]
understand  =np.delete(C_np,0,1)
for num in range(1,N+1): 
    for t in combinations(all_book,num): 
        book_buy        =np.array(t,dtype=int) 
        understand_now  = understand[book_buy] 
        understand_sum  = np.sum(understand_now, axis=0)
        if np.all(understand_sum >= X):
            price_now =price[book_buy]
            price_list.append(np.sum(price_now))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Solution (Python):
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        
N, M, X = map(int, input().split())
C_np    = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]

price       =C_np[:,0]
understand  =np.delete(C_np,0,1)

for num in range(1,N+1): 
    for t in combinations(all_book,num): 
        book_buy        =np.array(t,dtype=int) 
        understand_now  = understand[book_buy] 
        understand_sum  = np.sum(understand_now, axis=0)
        if np.all(understand_sum >= X):
            price_now =price[book_buy]
            price_list.append(np.sum(price_now))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Solution (Python):
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        
N, M, X = map(int, input().split())
items   = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]

for num in range(1,N+1): 
    for t in combinations(all_book,num): 
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            price_list.append(np.sum(tmp[0]))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Solution (Python):
n, m, x = map(int, input().split())

a = []
c = []

for i in range(n):
    a.append(list(map(int, input().split())))
    c.append(a[i][0])
    del a[i][0]

INF = 100000000

ans = INF

for i in range(1 << n):
    cost = 0
    d = [0] * m
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for k in range(m):
                d[k] += a[j][k]
    ok = True
    for j in range(m):
        if d[j] < x:
            ok = False
    if ok:
        ans = min(ans, cost)
if ans == INF:
    print(-1)
else:
    print(ans)

Solution (Python):
from itertools import combinations
import numpy as np
        
N, M, X = map(int, input().split())
items   = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out     = 10**18
flag    =False
price_list  =[]

for num in range(1,N+1): 
    for t in combinations(all_book,num): 
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            
            price_list.append(np.sum(tmp[0]))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Solution (Python):
from sys import stdin
input = stdin.readline

N, M, X = map(int, input().split())
pricelist = [0] * N
matrix = [[0] * M for _ in range(N)]
for i in range(N):
    row = list(map(int, input().split()))
    pricelist[i] = row.pop(0)
    matrix[i] = row

mintotalprice = 10**5 * 12 + 1
for bit in range(2**N):
    flag = True
    for j in range(M):
        totalscore = 0
        for i in range(N):
            if (bit>>i & 1) == 1:
                totalscore += matrix[i][j]
        if totalscore < X:
            flag = False
            break
    if flag:
        totalprice = 0
        for i in range(N):
            if (bit>>i & 1) == 1:
                totalprice += pricelist[i]
        mintotalprice = totalprice if mintotalprice > totalprice else mintotalprice
        
print(mintotalprice if mintotalprice != 10**5 * 12 + 1 else -1)

Solution (Python):
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]

p = []

for i in range(1, 2**N):
    buff = [0] * (M + 1)

    for j in range(N):
        if i >> j & 1:
            buff = [a + b for a, b in zip(buff, books[j])]

    for a in buff[1:]:
        if a < X:
            break
    else:
        p.append(buff[0])

if len(p) > 0:
    ans = min(p)
else:
    ans = -1

print(ans)

Solution (Python):
from itertools import combinations
import numpy as np
        
N, M, X = map(int, input().split())
items   = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out     = 10**18
flag    =False

for num in range(1,N+1): 
    for t in combinations(all_book,num): 
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            out = min(out, tmp[0])
            flag =True
if flag ==True:
    print(out)
else:
    print(-1)

Solution (Python):
from itertools import combinations
import numpy as np
        
N, M, X = map(int, input().split())
items = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out = 10**18

for num in range(1,N+1): 
    for t in combinations(all_book,num): 
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            out = min(out, tmp[0])

if out == 10**18:
  print(-1)
else:
  print(out)

Solution (Python):
n,m,x=(int(i) for i in input().split())
a=[]
c=[]
for i in range(n):
  a.append(list(map(int,input().split())))
  c.append(a[i][0])
  del a[i][0]
  
INF=1001001001
ans=INF

for s in range(1<<n):
  cost=0
  d=[0]*m
  for i in range(n):
    if(s>>i&1):
      cost+=c[i]
      for j in range(m):
        d[j]+=a[i][j]
  ok=True
  for j in range(m):
    if(d[j]<x):
      ok=False
  if ok:
    ans=min(ans,cost)
if ans==INF:
  print(-1)
else:
  print(ans)

Solution (Python):
N_satsu, M_ko, X = map(int, input().split())

Books = []
min_money = float('inf')

for i in range(N_satsu):
    tmp = list(map(int, input().split()))
    Books.append(tmp)


for i in range(2 ** N_satsu):
    sum_money = 0
    sum_skill = [0 for k in range(M_ko)]
    
    for j in range(N_satsu):
        bitt = i >> j
        if (bitt & 1):
            sum_money += Books[j][0]
            
            for _ in range(M_ko):
                sum_skill[_] += Books[j][_ + 1]
    
    judge = [l >= X for l in sum_skill]
    if (all(judge)):
        min_money = min(min_money, sum_money)

if (min_money != float('inf')):
    print(min_money)
else:
    print(-1)

Solution (Python):
import numpy as np
import itertools
n,m,x=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))


result = []

for n in range(1,len(a)+1):
    for conb in itertools.combinations(a, n):
        result.append(np.array(conb)) 

count = 0

ans = []

for i in range(len(result)):
    t = sum(result[i])
    
    for k in range(1,len(t)):
        
        if t[k] >= x:
            count += 1
        else:
            count = 0
            break
    if count == m:
        ans.append(t[0])
        count = 0
        
    
if len(ans) > 0:
    
    
    print(min(ans))
    
else:
    print(-1)

Solution (Python):
n,m,x = map(int,input().split())

A = [[] for _ in range(n)]
c = [0] * n

for i in range(n):
    c_as = list(map(int, input().split()))
    c[i], A[i] = c_as[0], c_as[1:]

INF = 10**9
ans = INF

for s in range(0,1 << n): 
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if (s >> i) % 2 == 0: continue
        cost_sum += c[i]
        for j in range(m):
            smart[j] += A[i][j]
    ok = True
    for j in range(m):
        if smart[j] < x:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

if ans == INF:
    ans = -1

print(ans)

Solution (Python):
n, m, x = list(map(int, input().split()))
cl = []
al = []

for i in range(n):
    c = input()
    a = []
    asum = 0
    for i, d in enumerate(c.split()):
        if i == 0:
            cl.append(int(d))
        else:
            a.append(int(d))
            
    al.append(a)


def filter(l, x):
    for e in l:
        if int(e) < x:
            return False
    return True


ok_price_list = []

for i in range(2**n):
    f = '0%db' % n
    si = format(i, f)
    price = [int(x) * int(y) for (x, y) in zip(si, cl)]
    point_sum = [0 for m in range(n)]
    for j, sb in enumerate(si):
        if sb == '1':
            point_sum = [x+y for (x, y) in zip(point_sum, al[j])]
    if filter(point_sum, x):
        ok_price_list.append(sum(price))
if len(ok_price_list) > 0:
    print(sorted(ok_price_list)[0])
else:
    print(-1)

Solution (Python):
def task(n, m, x, c, a):
    mx = [0] * m
    for i in range(0, n):
        for j in range(0, m):
            mx[j] += a[i][j]

    for j in range(0, m):
        if mx[j] < x:
            print(-1)
            return

    states = [0] * m

    best = 100000000
    for i in range(1, 2**n):
        price = 0

        for k in range(0, m):
            states[k] = 0

        for j in range(0, n):
            if ((i >> j) & 1):
                price += c[j]
                for k in range(0, m):
                    states[k] += a[j][k]

        if price < best:
            found = True
            for k in range(0, m):
                if states[k] < x:
                    found = False
                    break

            if found:
                best = price

    print(best)


n, m, x = map(int, input().split())
c = []
a = []
for i in range(0, n):
    values = list(map(int, input().split()))
    c.append(values[0])
    a.append(values[1:])

task(n, m, x, c, a)

Solution (Python):
import numpy as np
import itertools
n,m,x=map(int,input().split())
a=[]
b=[0]*m
skill=np.array([b])
ans=[]
money=0
for _ in range(n):
    a.append(list(map(int,input().split())))
for i in range(1,n+1):
    for j in itertools.combinations(range(1,n+1),i):
        for k in range(len(j)):
            money+=a[j[k]-1][0]
            skill+=np.array([a[j[k]-1][1:m+1]])
        if all([i>=x for i in skill[0]]):
            ans.append(money)
        money=0
        skill=np.array([b])
if len(ans)==0:
    print(-1)
else:
    print(min(ans))

Solution (Python):
def readinput():
    n,m,x=list(map(int,input().split()))
    dat=[]
    for i in range(n):
        s=list(map(int,input().split()))
        c=s[0]
        a=s[1:]
        dat.append((c,a))
    return n,m,x,dat

def makeTableA(dat,n,m):
    tbl=[[0]*m]*n
    
    for i in range(n):
        tup=dat[i]
        a=tup[1]
        
        
        
        tbl[i]=list(a) 
        
    return tbl  


def main(n,m,x,dat):
    tblA=makeTableA(dat,n,m)
    
    tblB=[[0]*(m+2)]*2**n  
    
    for i in range(2**n):
        tblB[i]=[0]*(m+2)
        b=1
        for j in range(n):
            if(i&b==b):
                for k in range(m):
                    
                    tblB[i][k]+=tblA[j][k]
                    
                tblB[i][m]+=dat[j][0]
                
            b=b*2
        tblB[i][m+1]=min(tblB[i][0:m])
        
    
    
    Pmin=12*10**5+1
    for i in range(2**n):
        if(tblB[i][m+1]>=x):
            price=tblB[i][m]
            if(price < Pmin):
                Pmin=price
    if(Pmin==12*10**5+1):
        Pmin=-1
    return Pmin


def readinput2():
    n,m,x = list(map(int,input().split()))
    tblA=[]
    c=[]
    for i in range(n):
        s=list(map(int,input().split()))
        c.append(s[0])
        tblA.append(s[1:])
    
    return n,m,x,c,tblA

def main2(n,m,x,c,a):
    tblB = [[0 for j in range(m+2)] for i in range(2**n)]
    for i in range(2**n):
        nn=1
        for j in range(n):
            
            if (i&nn==nn):
                for k in range(m):
                    tblB[i][k]+=a[j][k]
                tblB[i][m]+=c[j]
            nn=nn*2
        tblB[i][m+1]=min(tblB[i][:m])
        

    Pmin=12*10**5+1
    for i in range(2**n):
        if(tblB[i][m+1]>=x):
            price=tblB[i][m]
            if(price < Pmin):
                Pmin=price
    if(Pmin==12*10**5+1):
        Pmin=-1
    return Pmin


if __name__=='__main__':
    
    
    n,m,x,c,tblA=readinput2()
    ans=main2(n,m,x,c,tblA)
    print(ans)

Solution (Python):
import numpy as np
import itertools

N, M, X, B = *map(int, input().split()), np.array([])

class book:
    def __init__(self, price, *understanding):
        self.price = price
        self.understanding = np.array(understanding)
    def __add__(self, other):
        return book(self.price+other.price , *self.understanding+other.understanding)

for _ in range(N):
    B = np.append(B, book(*map(int, input().split())))

P = []
for i in range(2**N):
    temp = book(0, *[0]*M)
    for j in range(N):
        if ((i >> j) & 1):
            temp += B[j]
    P.append(temp)

P = np.array(list(filter(lambda x: all(X<=x.understanding),P)))
P = np.array(list(sorted(P, key=lambda x: x.price)))
try:
    print(P[0].price)
except IndexError:
    print(-1)

Solution (Python):
n,m,x=map(int,input().split())
l=[]
c=[]
l4=[]
for _ in range(n):
    k=list(map(int,input().split()))
    c.append(k[0])
    l.append(k[1:])

for i in range(2**n):
    l2=[]
    for j in range(n):
        if (i>>j)&1==1:
            l2.append(j)
    l3=[0]*m
    for jj in l2:
        for kk in range(m):
            l3[kk]+=l[jj][kk]
    if min(l3)>=x:
        count=0
        for kkk in l2:
            count+=c[kkk]
        l4.append(count)
if l4==[]:
    print(-1)
else:
    print(min(l4))

Solution (Python):
n,m,x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
ans_cost = []

def calc_cost(book, next_book):
  result = []
  for i, a in enumerate(next_book):
    result.append(book[i] + a) 
  return result

def search_cost(num, sum_book):
  if num >= n:
    for a in sum_book[1:]:
      if a < x:
        return
    ans_cost.append(sum_book[0])
    return
  next_book = calc_cost(sum_book, books[num])
  num += 1
  search_cost(num, next_book)
  search_cost(num, sum_book)

empty_book = [0 for _ in range(m+1)]
search_cost(0, empty_book)
if len(ans_cost) ==0 :
  print(-1)
else:
  print(min(ans_cost))

Solution (Python):

n, m, x = list(map(int, input().split()))
c = []
a = []
for i in range(n):
    t = list(map(int, input().split()))
    c.append(t[0])
    a.append(t[1:])
    
    
result = -1
for i in range(1 << n):
    reading_books = [0 for _ in range(m)]
    cost = 0
    for j in range(n):
        if (i >> j) & 1 == 0:
            continue
        cost += c[j]
        for k in range(m):
            reading_books[k] += a[j][k]
        if all(skill >= x for skill in reading_books):
            if result == -1:
                result = cost
            else:
                result = min(result, cost)


print(result)

Solution (Python):
n, m, x = map(int, input().split())
books = []
for i in range(n):
	books.append(tuple(map(int, input().split())))

def combinations():
	from itertools import product
	
	for i in product([0, 1], repeat = n):
		lst = []
		for j in range(n):
			if i[j] == 1:
				lst.append(books[j])
		yield lst

ans = 10**9
for books_bought in combinations():
	level = [0]*m
	cost = 0
	for book in books_bought:
		cost += book[0]
		for i in range(m):
			level[i] += book[i + 1]
		
	for num in level:
		if num < x:
			break
	else:
		ans = min(ans, cost)

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

Solution (Python):
n, m, x = map(int, input().split())
books = []
for i in range(n):
	books.append(tuple(map(int, input().split())))

def combinations():
	from itertools import product
	
	for i in product([0, 1], repeat = n):
		lst = []
		for j in range(n):
			if i[j] == 1:
				lst.append(books[j])
		yield lst

ans = 10**9
for books_bought in combinations():
	level = [0]*m
	cost = 0
	for book in books_bought:
		cost += book[0]
		for i in range(m):
			level[i] += book[i + 1]
		
	for num in level:
		if num < x:
			break
	else:
		ans = min(ans, cost)

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

Solution (Python):
def main():
    n,m,x = map(int, input().split())
    c = [None]*n
    a = [None]*n
    
    for i in range(n):
        line = list(map(int, input().split()))
        c[i] = line[0]
        a[i] = line[1:]
    
    costs = []
    
    def func(i, points, cost, x):
        if i == n:
            if all([point >= x for point in points]):
                costs.append(cost)
            else:
                return None
        
        if all([point >= x for point in points]):
            costs.append(cost)
            return None
        
        func(i+1, points, cost, x)
        func(i+1, [points[j] +a[i][j] for j in range(m)], cost+c[i], x)
    
    func(0, [0]*m, 0, x)
    
    if len(costs) == 0:
        return -1
    
    return min(costs)

print(main())

Solution (Python):
N,M,X = [int(i) for i in input().split()]
A = []
for _ in range(N):
    A.append([int(i) for i in input().split()])
ans = float("inf")

for i in range(1,2**N):
    a = 0
    e = [0]*M
    bi = "0"*N + bin(i)[2:]
    bi = list(bi[len(bi)-N:])
    for j in range(N):
        if bi[j] == "1":
            a += A[j][0]
            for k in range(M):
                e[k] += A[j][k+1]
    c = True
    for i in range(M):
        c &= e[i] >= X
    if c:
        ans = min(ans,a)
if ans > 10**7:
    print(-1)
else:
    print(ans)

Solution (Python):
def main():
    n,m,x = map(int, input().split())
    c = [0]*n
    a = [0]*n
    
    for i in range(n):
        line = list(map(int, input().split()))
        c[i] = line[0]
        a[i] = line[1:]
    
    costs = []
    
    def func(i, points, cost, x):
        if i == n:
            if all([point >= x for point in points]):
                costs.append(cost)
            else:
                return None
        
        if all([point >= x for point in points]):
            costs.append(cost)
            return None
        
        func(i+1, points, cost, x)
        func(i+1, [points[j] +a[i][j] for j in range(m)], cost+c[i], x)
    
    func(0, [0]*m, 0, x)
    
    if len(costs) == 0:
        return -1
    
    return min(costs)

print(main())

Solution (Python):
INF = float('inf')
import copy
 
def dfs(i, C):
    if i == N:
        if min(C[1:]) >= X:
            return C[0]
        else:
            return INF
    res = INF
    res = min(res, dfs(i+1, copy.copy(C)))
    for j in range(M+1):
        C[j] = C[j] + L[i][j]
    res = min(res, dfs(i+1, copy.copy(C)))
    return res

N, M, X = map(int, input().split())
L = [[int(x) for x in input().split()] for _ in range(N)]

ans = dfs(0, [0 for _ in range(M+1)])
if ans == INF:
    ans = -1
print(ans)

Solution (Python):
def bit_set(num:int,n:int):
  if num & (1<<n):
    return True
  return False

n,m,x = map(int,input().split())
ca_list = [list(map(int,input().split())) 
           for nesya in range(n)]
c = -1
for i in range(2**n):
  skill = [0]*m
  cost = 0
  for k in range(n):
    if bit_set(i,k) == True:
      ca =  ca_list[k]
      cost += ca[0]
      a = ca[1:]
      skill = [j+l for (j,l) in zip(skill, a)]
  if all((hoge >= x) for hoge in skill):
    if c == -1:
      c = cost
    else:
      c = min(c,cost)
print(c)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,x = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(n)]
    ans = float("inf")

    for b in range(1<<n):
        cost = 0
        k = [0]*m
        for i in range(n):
            if b&(1<<i): 
                cost += s[i][0] 
                for j in range(m):
                    k[j] += s[i][j+1] 
        if cost < ans and all([i >= x for i in k]):
            ans = cost
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
import numpy as np
from itertools import product

def readlines(n):
    for _ in range(n):
        yield list(map(int, input().split()))

def main():
    N, M, X = map(int, input().split())

    books = np.array(list(readlines(N)))
    ans = np.inf
    for bit in product([0, 1], repeat=N):
        comb_sum = np.dot(np.array(bit), books)
        if all(comb_sum[1:] >= X):
            ans = min(ans, comb_sum[0])

    if ans == np.inf:
        print(-1)
    else: 
        print(ans)
        


main()

Solution (Python):
import sys
import itertools
n, m, x=map(int, input().split())
text = [list(map(int, i.strip('\n').split())) for i in sys.stdin]
num_tex = [i for i in range(1, len(text) + 1)]
all_c = []
for comb in num_tex:
    for v in itertools.combinations(text, comb):
        sum_a = []
        for j in range(1, len(v[0])):
            sum_a.append(sum([v_[j] for v_ in v]))
        if all([x <= sum_a_ for sum_a_ in sum_a]):
            all_c.append(sum([v_[0] for v_ in v]))
if len(all_c)!=0:
    print(sorted(all_c)[0])
else:
    print(-1)

Solution (Python):
import numpy as np
n,m,x = map(int,input().split())
t = [ i + 1 for i in range(0,n)]
res = []
for i in range(n):
    c_a = list(map(int,input().split()))
    res.append(c_a)
import itertools
choice = []
def all_choice(x,n):
    for i in x:
        for j in itertools.combinations(range(0,n), i):
            choice.append(j)
    return choice
all_choice = all_choice(t,n)
count = []
for a in all_choice:
    res_0 = np.array([res[i] for i in a])
    flag = 0
    for i in range(m):
        if sum([t[i+1] for t in res_0]) < x:
            flag = 1
            break
    if flag == 0:
        count.append(sum([t[0] for t in res_0]))
if len(count)==0:
    print(-1)
else:
    print(min(count))

Solution (Python):
import itertools
n,m,x=map(int,input().split())
c=[0]*n
a=[[0 for i in range(m)] for j in range(n)]
current_skill=[0]*m
INF=9999999
min_money=INF


for  i in range(n):
    tmp=list(map(int,input().split()))
    c[i]=tmp[0]
    a[i]=tmp[1:]

current_money=0

for i in range(1 << n):
    bug=[]
    for j in range(n):
        if (i>>j) &1:
            bug.append(j)
    current_skill=[0]*m
    current_money=0
    for chosen_set_num in bug:
        current_money+=c[chosen_set_num]
        for each_book_num in range(m):
            current_skill[each_book_num]+=a[chosen_set_num][each_book_num]
            

        if all(status >=x for status in current_skill ):
            min_money=min(min_money,current_money)
            continue
if min_money==INF:
    min_money=-1
print(min_money)

Solution (Python):
def dfs(bit):
    if len(bit)==N:
        c=0
        s=[0 for _ in range(M)]
        for i in range(N):
            c+=A[i][0]*bit[i]
            if bit[i]==1:
                for j in range(M):
                    s[j]+=A[i][j+1]
                cond=True
                for k in range(M):
                    if s[k]<X:
                        cond=False
                        break
                if cond:
                    ans.append(c)
        return

    else:
        for i in range(2):
            bit.append(i)
            dfs(bit)
            bit.pop()
    
N,M,X=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N)]

ans=[]

dfs([])

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

Solution (Python):
N, M, X = map(int, input().split())
box = [list(map(int, input().split())) for _ in range(N)]


ans = -1
for i in range(2 ** N):
    p = [0 for _ in range(M)]
    kakaku = 0
    for j in range(N):
        if (i >> j) & 1:
            kakaku += box[j][0]
            for n, k in enumerate(box[j][1:]):
                p[n] += k
    if all(el >= X for el in p):
        if ans == -1:
            ans = kakaku
        else:
            ans = min(ans, kakaku)
print(ans)

Solution (Python):
def skill_up(books_costs, books_knowledge, target):
    def add_book(aggr_knowledge, aggr_cost, idx):
        for i, algo in enumerate(books_knowledge[idx]):
            aggr_knowledge[i] += algo
        aggr_cost += books_costs[idx]
        return aggr_knowledge, aggr_cost

    def remove_book(aggr_knowledge, aggr_cost, target, idx):
        potential_comb = True
        for i, algo in enumerate(books_knowledge[idx]):
            aggr_knowledge[i] -= algo
            potential_comb &= aggr_knowledge[i] >= target
        aggr_cost -= books_costs[idx]
        return aggr_knowledge, aggr_cost, potential_comb
    
    def min_cost_skill_up(aggr_knowledge, aggr_cost, idx, target):
        if idx == len(books_knowledge):
            return aggr_cost

        min_cost = aggr_cost

        min_cost = min(min_cost, min_cost_skill_up(aggr_knowledge, aggr_cost, idx+1, target))

        aggr_knowledge, aggr_cost, potential_comb = remove_book(aggr_knowledge, aggr_cost, target, idx)
        if potential_comb:
            min_cost = min(min_cost, min_cost_skill_up(aggr_knowledge, aggr_cost, idx+1, target))
        aggr_knowledge, aggr_cost = add_book(aggr_knowledge, aggr_cost, idx)

        return min_cost

    aggr_knowledge = [0 for _ in range(len(books_knowledge[0]))]
    aggr_cost = 0
    for i in range(len(books_knowledge)):
        aggr_knowledge, aggr_cost = add_book(aggr_knowledge, aggr_cost, i)

    if not all([algo_knowledge >= target for algo_knowledge in aggr_knowledge]):
        return -1

    return min_cost_skill_up(aggr_knowledge, aggr_cost, 0, target)


book_count, algorithm_count, target = map(int, input().split(' '))
books_knowledge = [[0 for _ in range(algorithm_count)] for _ in range(book_count)]
books_costs = [0 for _ in range(book_count)]

for i in range(book_count):
    book = list(map(int, input().split(' ')))
    books_costs[i] = book[0]
    books_knowledge[i] = book[1:]

print(skill_up(books_costs, books_knowledge, target))

Solution (Python):
import itertools

N, M, X = map(int, input().split())
List = [list(map(int, input().split())) for n in range(N)]
INF = 10**7
ans = INF
C_pro = list(itertools.product([0,1], repeat=N))

for c_pro in C_pro:
    count = 0
    cost = 0
    ans_list = [0 for i in range(M)]
    for c in c_pro:
        if c == 1:
            cost += List[count][0]
            ans_list = [answ+list for answ, list in zip(ans_list,List[count][1:])]
        count += 1
    ok = True
    for i in range(len(ans_list)):
        if ans_list[i] < X:
            ok = False
            break
    if ok:
        ans = min(ans, cost)
    

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

Solution (Python):
n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]

total_all = []
for i in range(2**n):
    b = [0]*m
    total = 0
    check = 'OK'
    for j in range(n):
        if ((i >> j) & 1):
            total += a[j][0]
            for k in range(1,m+1):
                b[k-1] += a[j][k]
    for l in range(m):
        if b[l] < x:
            check = 'NG'
            break
    if check == 'OK':
        total_all.append(total)
if len(total_all) == 0:
    print(-1)
else:
    print(min(total_all))