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):
import sys 
try:
	sys.stdin = open('Input.txt', 'r') 
	sys.stdout = open('Output.txt', 'w')
except:
	pass

input = sys.stdin.readline

def Buy(books,threshold):
	if len(books) == 0:
		for k in threshold:
			if k<x:
				return float('inf')
		else:
			return 0
			
	thresholdnew = threshold[:]
	for k in range(m):
		thresholdnew[k] += books[0][k+1]
	return min(Buy(books[1:],threshold),books[0][0]+Buy(books[1:],thresholdnew))

n,m,x = map(int,input().split())
books = []

for i in range(n):
	l = list(map(int,input().split()))
	books.append(l)
	threshold = [0]*m

ans = Buy(books,threshold)

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

Solution (Python):
N,M,X = map(int,input().split())
book = [0] * N
total = [0] * M
point = [[] for i in range(N)]
ans = 10 ** 9

for i in range(N):
  a = list(map(int,input().split()))
  book[i] = a[0]
  point[i] = a[1:]
  for j in range(M):
    total[j] += point[i][j]

if any([i < X for i in total]):
  print(-1)
else:
  for i in range(2 ** N):
    pattern = [0] * M
    cost = 0
    for j in range(N):
      if (i >> j) & 1:
        pattern = [pattern[t] + point[j][t] for t in range(M)]
        cost += book[j]
    if all([i >= X for i in pattern]):
      ans = min(ans,cost)
  print(ans)

Solution (Python):
n,m,x=map(int,input().split())
price_points=[]
for i in range(n):
    line=list(map(int,input().split()))
    price_points.append(line)
sum_list=[]
for i in range(2**n):
    i=bin_str = format(i, 'b')
    
    i_len=len(i)
    i_n_bit="0"*(n-i_len)+i
    sum_=0
    points=[0]*m
    for j in range(n):
        if i_n_bit[j]=="0":
            continue
        else:
            sum_+=price_points[j][0]
            for k in range(m):
                points[k]+=price_points[j][k+1]
    counter=0
    for l in range(m):
        if points[l]>=x:
            counter+=1    
    if counter==m:
        sum_list.append(sum_)
if len(sum_list)==0:
    print(-1)
else:
    print(min(sum_list))

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

pattern = []
for i in range(2**n):
    tmp = [0 for i in range(n)]
    for j in range(n):
        if i >> j & 1:
            tmp[j] = 1
    pattern.append(tmp)

ans = []
for i in pattern:
    l = [0 for j in range(m+1)]
    for j in range(n):
        if i[j]:
            for k in range(m+1):
                l[k] += lis[j][k]
    
    flag = 1
    for j in range(1, m+1):
        if l[j] < x:
            flag = 0
            break
    if flag:
        ans.append(l[0])
if not len(ans):
    print(-1)
else:
    print(min(ans))

Solution (Python):

import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 

n,m,x=map(int,input().split())
e=[]
tot=999999999999999999999999999
def binary(n,ju):
    binaryNum = [0] * (ju) 
    i = 0
    while (n > 0):  
        binaryNum[i] = n % 2 
        n = int(n / 2) 
        i += 1 
    binaryNum.reverse()
    return binaryNum
for i in range(n):
    e.append(list(map(int,input().split())))
for i in range(0,2**(n)):
    ans=[0]*m
    s=binary(i,n)
    cost=0
    
    for j in range(n):
        if s[j]==1:
            cost+=e[j][0]
            for k in range(m):
                ans[k]+=e[j][k+1]
    f=0
    for j in ans:
        if j<x:
            f=1
            break
    if f==0:
        tot=min(tot,cost)
if tot==999999999999999999999999999: 
    print(-1)
else:
    print(tot)

Solution (Python):
N,M,X = map(int,input().split())
ans = []
CAs = [[int(i) for i in input().split()] for j in range(N)]
for i in range(1<<N):
    rikai = [0 for k in range(M)]
    res = 0
    for j in range(N):
        if (i>>j) & 1:
            res += CAs[j][0]
            for s in range(1,M+1):
                rikai[s-1] += CAs[j][s]
    for j in rikai:
        if j<X:
            res = -1
    ans.append(res)

ans = set(ans)
ans.discard(-1)
if ans:
    print(min(ans))
else:
    print(-1)

Solution (Python):
import sys
import math
import itertools

def main():
  n,m,x = map(int, input().split())
  books = []
  [books.append(list(map(int, input().split()))) for _ in range(n)]

  canMoney = []
  for i in range(n):
    for book_comb in itertools.combinations(books, i+1):
      sum = [0 for _ in range(m+1)]
      for book in book_comb:
        for j in range(m+1):
          sum[j] += book[j]
      
      enough = True
      for s in range(len(sum)-1):
        if sum[s+1] < x:
          enough = False
          break
      if enough:
        canMoney.append(sum[0])

  if len(canMoney) == 0:
    print('-1')
  else:
    canMoney.sort()
    print(canMoney[0])


if __name__ == '__main__':
  main()

Solution (Python):
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
sys.setrecursionlimit(150000)

N, M, X = map(int, sys.stdin.readline().split())
a = []
for i in range(N):
    a.append(inpl())
b = [0] * M
res = float("INF")
def DFS(cost, start, temp):
    global res
    if min(temp) >= X:
        res = min(res, cost)
        return res
    for i in range(start, N):
        c = temp.copy()
        d = [i + j for i, j in zip(c, a[i][1:])]
        DFS(cost + a[i][0], i + 1, d)
    return res

ans = DFS(0,0,b)
if ans != float("INF"):
    print(ans)
else:
    print(-1)

Solution (Python):
from itertools import combinations

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

    row = []

    ans = 10 ** 10

    for i in range(N):
        row.append(list(map(int, input().split())))

    for k in range(1, N+1):
        co = list(combinations(row, k))

        for t in co:
            cost = 0
            skill = [0] * M
            for v in t:
                cost += v[0]
                for s in range(M):
                    skill[s] += v[s+1]

            if(min(skill) >= X):
                ans = min(ans, cost)

    if(ans == 10 ** 10):
        ans = -1

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def m():
    N, M, X = map(int, input().split())
    CA = [list(map(int, input().split())) for _ in range(N)]
    ans = float('inf')
    for i in range(2 ** N):
        b = bin(i)[2:]
        b = b.zfill(N)
        tmp = [0] * (M + 1)
        for j, v in enumerate(b):
            if v == '0':
                continue
            tmp[0] += CA[j][0]
            for k in range(1, M + 1):
                tmp[k] += CA[j][k]
        f = 1
        for p in range(1, M + 1):
            if tmp[p] < X:
                f = 0
                break
        if f == 0:
            continue
        ans = min(ans, tmp[0])
    if ans == float('inf'):
        return '-1'
    else:
        return ans


print(m())

Solution (Python):
from itertools import product
n, m, x = map(int, input().split())
C = []
A = []
for _ in range(n):
    temp = list(map(int, input().split()))
    C.append(temp[0])
    A.append(temp[1:])

ans = float('inf')
for i in product([True, False], repeat=n):
    alg = [0]*m
    cost = 0
    for id, j in enumerate(i):
        c = C[id]
        a = A[id]
        if j:
            for k in range(m):
                alg[k]+=a[k]
            cost+=c
    if min(alg)>=x: ans=min(ans, cost)
if ans==float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
Line = [int(s) for s in input().split()]
n,M,X = Line[0],Line[1],Line[2]

ans = -1
money = []

item = [0]*n




for i in range(n):
    item[i] = [int(s) for s in input().split()]


for i in range(2 ** n):
    bag = []
    algos = [0]*M
    
    total = 0
    for j in range(n):  
        if ((i >> j) & 1):  
            bag.append(item[j][0])  
            total += item[j][0]  
            for x in range(M):
                algos[x] += item[j][x+1]
    
            
    if (all(elem >= X for elem in algos)):
        
        ans = 1
        money.append(total)
if ans == 1:
    print(min(money))
else:
    print(-1)

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

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

N_list = list(range(N))

price_list = []
point_list = []

x = []

for i in range(N):
  my_list = list(map(int, input().split()))
  price_list.append(my_list[0])
  point_list.append(my_list[1:])
  x.append(list(combinations(N_list, i+1)))

my_np = np.array(point_list)

ans = None

for i in x:
  for j in i:
    check_price = 0
    check_np = np.zeros(M)
    for k in j:
      check_price += price_list[k]
      check_np += my_np[k]
    if min(check_np) >= X:
      if ans is None:
        ans = check_price
      else:
        ans = min(check_price,ans)

if ans is None:
  ans = -1

print(ans)

Solution (Python):
from itertools import combinations
N, M, X = map(int, input().split())
CAs = [[int(n) for n in input().split()] for _ in range(N)]

MAX = 10 ** 5 * 12 + 1
min_ = MAX

for i in range(1, N + 1):
    for cas in combinations(CAs, i):
        rikai = [0] * M
        kakaku = 0
        for ca in cas:
            for j in range(M):
                rikai[j] += ca[j + 1]
            kakaku += ca[0]
        if len(list(filter(lambda x: x < X, rikai))) == 0:
            min_ = min(min_, kakaku)
if min_ == MAX:
    print('-1')
else:
    print(min_)

Solution (Python):
import itertools

n, m, x = (int(each) for each in input().split())

books = []
for i in range(n):
    books.append([int(each) for each in input().split()])



scores = []
products = itertools.product([0,1], repeat=n)
for pro in products:
    score = [0]*(m+1)
    for index, j in enumerate(pro):
        if j == 1:
            score = [x+y for (x, y) in zip(score, books[index])]
    if min(score[1:]) >= x:
        scores.append(score)

if len(scores) == 0:
    print(-1)
else:
    print(min([each[0] for each in scores]))

Solution (Python):
import itertools
N,M,X = map(int,input().split())
costs = []
books = []
for _ in range(N):
    entry = list(map(int,input().split()))
    costs.append(entry[0])
    books.append(entry[1:])
    
mxcost = sum(costs) + 1
lst = [list(i) for i in itertools.product([0, 1], repeat=N)]
for item in lst:
    cost = sum([item[0]*item[1] for item in zip(costs,item)])
    Xs = [0] * M
    for i in range(N):
        if item[i] == 1:
            for j in range(M):
                Xs[j] += books[i][j]
    if min(Xs) >= X:
        mxcost = min(mxcost,cost)

if mxcost == sum(costs) + 1:
    print(-1)
else:
    print(mxcost)

Solution (Python):

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

l=[list(map(int,input().split())) for i in range(n)]

def tas(l1,l2):
    l3=[]
    for i in range(m+1):
        l3.append(l1[i]+l2[i])
    return l3


ll=[[0 for i in range(m+1)]]
for i in range(n):
    for j in range(len(ll)):
        ll.append(tas(ll[j],l[i]))

lm=[]
for i in ll:
    lll=[]
    for j in range(1,len(i)):
        if i[j]>=x:
            lll.append(True)
        else:
            lll.append(False)
    if all(lll)==True:
        lm.append(i[0])

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

Solution (Python):
import itertools

n,m,x=map(int,input().split())
c=[0]*n
a=[[0]*m for i in range(n)]
for i in range(n):
    l=list(map(int,input().split()))
    c[i]=l[0]
    a[i]=l[1:len(l)]
    
cmin=10**7
yn2=""
for i in itertools.product([0,1], repeat=n):
    csum=0
    yn=""
    asum=[0]*m
    for ii in range(len(i)):
        if i[ii]==1:
            for j in range(m):
                asum[j]+=a[ii][j]
            csum+=c[ii]
    for j in range(m):        
        if asum[j]<x:
            yn="no"
            break
    if yn!="no":

        cmin=min(cmin,csum)
        yn2="yes"

if yn2=="yes":
    print(cmin)                
else:
    print(-1)

Solution (Python):
import numpy as np

N, M, X = map(int, input().split())
C = np.array([[int(i) for i in input().split()] for j in range(N)])

memo = np.array([0 for i in range(M)])

def check(memo):
    for i in memo:
        if i < X:
            return False
    return True

def rec(i, cost, memo):
    if i == N:
        if check(memo):
            return cost
        return float("inf")
    
    
    
    return min(rec(i+1, cost, memo), rec(i+1, cost+C[i, 0], memo+C[i, 1:]))

ans = rec(0, 0, memo)
if ans != float("inf"):
    print(ans)
else:
    print(-1)

Solution (Python):
N,M,X = map(int,input().split())

L = [list(map(int,input().split()))  for i in range(N)]

cost = 10**12

import itertools

S = list(itertools.product([0,1],repeat=N))


for i in S:
    cnt = 0
    ablity = [0] * M
    for j in range(N):
        if i[j] == 1:
            for k in range(M+1):
                if k == 0:
                    cnt += L[j][k]
                    
                else:
                    ablity[k-1] += L[j][k]
    
    ans = True
    for i in ablity:
        if i < X:
            ans = False
    
    if ans:
        cost = min(cost,cnt)
        
if cost == 10**12:
    print(-1)
else:
    print(cost)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)

N, M, X = map(int, input().split())
Matrix = []

for _ in range(N):
    row = list(map(int, input().split()))
    Matrix.append(row)

U = [0] * (M + 1)
def rec(ans, pos):
    if pos == N:
        return ans
    row = Matrix[pos]
    for i in range(M  + 1):
        U[i] += row[i]

    for u in U[1:]:
        if u < X:
            ans = min(rec(ans, pos + 1), ans)
            break
    else:
        ans = min(U[0], ans)

    for i in range(M  + 1):
        U[i] -= row[i]
    return min(rec(ans, pos + 1), ans)

ans = rec(float('inf'), 0)
if ans == float('inf'):
    ans = -1
print(ans)

Solution (Python):
n, m, x = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(n)]
ans = 10 ** 9
for i in range(2 ** n):
    sumA = [0 for i in range(m)]
    cost = 0
    for j in range(n):
        if ((i >> j) & 1):
            cost += C[j][0]
            for k in range(m):
                sumA[k] += C[j][k + 1]
    flag = True
    for l in range(m):
        if sumA[l] < x:
            flag = False
            break
    if flag:
        ans = min(ans, cost)
        
if ans == 10 ** 9:
    print(-1)
else:
    print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np

    N, M, X = map(int, input().split())
    CA = np.array([list(map(int, input().split())) for i in range(N)])

    Z = [list(format(i, '0{}b'.format(N))) for i in range(2**N)]

    cost = np.inf
    for z in Z[1:]:
        ind = np.array(z) == '1'
        ca = np.sum(CA[np.where(ind)], axis=0)
        if np.sum(ca[1:] >= X) == M:
            cost = min(cost, ca[0])
    if cost == np.inf:
        cost = (-1)
    print(cost)


if __name__ == "__main__":
    main()

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

n,m,x = map(int, input().split())
q = [np.array(list(map(int, input().split()))) for _ in range(n)]
L=[]
for i in range(1,n+1):
    for j in list(combinations(q,i)):
        S = np.sum(j, axis=0)
        if all([k >= x for k in S[1:]]):
            L.append(S[0])

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

Solution (Python):
from sys import stdin
N,M,X=list(map(int,(stdin.readline().strip().split())))
cost=[]
money=0
und=[0]*M
sankousho=[]
for i in range(N):
    book = list(map(int, (stdin.readline().strip().split())))
    sankousho.append(book)
def hantei(und):
    for i in und:
        if i<X:return False
    return True
def kiroku(b,und):
    for i in range(M):
        und[i]+=b[i+1]
    return und
def use(book,i,money,und):
    money_A=money
    money_B=money
    und_A=und.copy()
    und_B=und.copy()
    if i==N:
        if hantei(und):
            cost.append(money)
    else:
        und_A=kiroku(book[i],und_A)
        money_A+=book[i][0]
        use(book,i+1,money_A,und_A)
        use(book,i+1,money_B,und_B)

use(sankousho,0,0,und)
if len(cost)==0:print(-1)
else:print(min(cost))

Solution (Python):
import numpy as np
N, M, X = (int(i) for i in input().split())  
arr = []
c_list = []
for _ in range(N):
  A = [int(i) for i in input().split()] 
  c_list.append(A[0])
  arr.append(A[1:])

comb_list = []
def recur(N, lis):
  comb_list.append(lis)
  if len(lis) == N:
    return
  
  for i in range(lis[-1]+1, N):
    recur(N, lis + [i])  

for i in range(N):
  recur(N, [i])

ans = np.inf
for Z in comb_list:
  tmp = np.zeros(M)
  tmp_c = 0
  for z in Z:
    tmp += arr[z]
    tmp_c += c_list[z]
  if np.all(tmp >= X):
    ans = min(ans, tmp_c)

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

Solution (Python):
from itertools import combinations
import numpy as np
n,m,x=map(int, input().split())

S = []
for i in range(n):
    A=list(map(int, input().split()))
    S.append(A)

ans = 10**9
for i in range(1,n+1):
    for comb in combinations(S,i):
        
        tmp = np.array([0]*m)
        
        cost = 0
        for s in comb:
            tmp += np.array(s[1:])
            cost += s[0]
        
        
        cnt = 0
        for t in tmp:
            if t >= x: cnt+=1
        
        if cnt == m:
            ans = min(ans,cost)
if ans == 10**9:
    print(-1)
else:
    print(ans)

Solution (Python):
N,M,X = [int(i) for i in input().split(' ')]

A = []
C = []

for i in range(N):
	tmp = [int(i) for i in input().split(' ')]
	C.append(tmp[0])
	A.append(tmp[1:])

import itertools
count = -1
m_li = []
lis = list(range(N))
for i in range(1, N+1):
	for pair in itertools.combinations(lis, i):
		count += 1
		money = 0
		Ad = [0]*M
		for j in pair:
			money += C[j]
			for ind,k in enumerate(A[j]):
				Ad[ind] += k
              	
		flag = True
		for j in range(M):
			if Ad[j]<X:
				flag = False
		if flag:
			m_li.append(money)

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

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

matrix = np.array(book, dtype="int")
decide = np.array(list(itertools.product([True,False],repeat=n)))
decide = decide[:-1]
money = -1
for i in range(len(decide)):
    test = np.sum(matrix[np.where(decide[i,:]),:], axis = 0)
    test = np.sum(test, axis = 0)
    
    
    
    if np.sum(test[1:]>=x) == m and (money > test[0] or money == -1):
        
        money = test[0]
if money == 1e6:
    print("-1")
else :
    print(money)

Solution (Python):
import numpy as np

N, M, X = map(int, input().split())
Cs, As = [], []
ans = float("inf")

for _ in range(N):
    row = list(map(int, input().split()))
    C, A = row[0], row[1:]
    Cs.append(C)
    As.append(A)

As = np.array(As)

for i in range(2 ** N):
    tmp_A = np.array([0] * M)
    tmp_ans = 0
    for j in range(N):
        if (i >> j) & 1:
            tmp_ans += Cs[j]
            tmp_A += As[j]
    cnt = 0
    for j in range(M):
        if tmp_A[j] >= X:
            cnt += 1
    if cnt == M:
        ans = min(ans, tmp_ans)

if ans == float("inf"):
    print(-1)
else:
    print(ans)

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


ans = float("inf")

for bit in range(1 << n):
    count = 0
    sum = [0]*m
    for i in range(n):
        if bit & (1 << i):
          for j in range(1,m+1):
            sum[j-1] += ca[i][j]
          count+=ca[i][0]
    for i in range(m):
      if sum[i]<x:
        break
      if i+1==m:
        ans=min(count,ans)
if ans==float("inf"):
  print(-1)
  exit()
print(ans)

Solution (Python):
n, m, x = map(int, input().split())
ca_list = []
budget_list = []

for _ in range(n):
  ca_list.append(input())

for i in range(2 ** n):
  bit_list = []
  for j in range(n):
    if (i >> j) & 1:
      bit_list.append(j)
  
  budget = 0
  point_list = [0] * m
  for b in bit_list:
    text = list(map(int, ca_list[b].split()))
    point_list = [x + y for (x, y) in zip(text[1:], point_list)]
    budget += text[0]
  
  if min(point_list) >= x:
    budget_list.append(budget)

if budget_list == []:
  print('-1')
else:
  print(min(budget_list))

Solution (Python):
import numpy as np

n, m, x = list(map(int, input().split()))
a_list = []
c_list = []
for _ in range(n):
  _a_list = list(map(int, input().split()))
  a_list.append(_a_list[1:])
  c_list.append(_a_list[0])

def ok(a_l):
  if a_l and min(np.sum(a_l, axis=0))>=x:
    return True
  else:
    return False

def dfs(l, i):
  if i==len(a_list) and not ok(l):
    return -1
  elif ok(l):
    return 0
  left = dfs(l+[a_list[i]], i+1)
  right = dfs(l, i+1)
  if left>=0 and right>=0:
    if left + c_list[i]<right:
      return left + c_list[i]
    elif left + c_list[i]>=right:
      return right
  elif left>=0 and right<0:
    return left + c_list[i]
  elif left<0 and right>=0:
    return right
  else:
    return min(left, right)

print(dfs([], 0))

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

for i in range(n):
    if i == 0:
        tmp = [kkk for kkk in range(n)]
        
        
        
        
        for t in tmp:
            score_li = [0]*m
            okane = 0
            
            for ii,ll in enumerate(list(li[t])):
                if ii==0:
                    okane += li[t][ii]
                else:
                    
                    score_li[ii-1]+=ll
            flag = True
            
            for ss in score_li:
                if ss<x:
                    flag = False
            if flag:
                ans_li.append(okane)

    else:
        tmp = list(itertools.combinations(range(n), i+1))
        
        
        
        
        for t in tmp:
            score_li = [0]*m
            okane = 0
            
            for aaa in t:
                for ii,ll in enumerate(list(li[aaa])):
                    if ii==0:
                        okane += li[aaa][ii]
                    else:
                        
                        score_li[ii-1]+=ll
            flag = True
            for ss in score_li:
                if ss<x:
                    flag = False
            if flag:
                ans_li.append(okane)

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

Solution (Python):


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

li = [f'{i:012b}' for i in range(2**N)]
C = []
A = []
for i in range(N):
    B = list(map(int, input().split()))
    C.append(B[0])
    A.append(B[1:])

d = []
for l in li:
    b = l[::-1][:N]
    rikai = [0]*M
    pri = [0]*N
    for i in range(len(b)):
        if b[i] == '1':
            for j in range(M):
                rikai[j] += A[i][j]
            pri[i] += C[i]
    d.append((sum(pri), rikai))

ans = 10**100
for s in d:
    f = True
    for r in s[1]:
        if r < X:
            f = False
            break
    if f:
        ans = min(ans, int(s[0]))
if ans == 10**100:print(-1)
else: print(ans)