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):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m,x = mi()

d = []
for i in range(n):
    d.append(li())

mincost = 10**10
for i in range(2**n):
    cost = 0
    tsd = [0] * m
    for j in range(n):
        if (i >> j)&1 == 1:
            cost += d[j][0]
            for k in range(m):
                tsd[k] += d[j][k+1]
    
    
    for j in range(m):
        if tsd[j] < x:
            break
    else:
        mincost = min(cost,mincost)

if mincost == 10**10:
    print(-1)
else:
    print(mincost)

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M, X = iim()
    S = [tuple(iim()) for i in range(N)]

    M1 = M+1
    mx = float("inf")
    ans = mx
    for i in range(1, 2**N):

        sx = [0]*(M1)
        for j in range(N):
            if i & (1<<j) == 0:
                continue

            for k, x in enumerate(S[j]):
                sx[k] += x

        if all(si >= X for si in sx[1:]):
            ans = min(ans, sx[0])

    if ans == mx:
        ans = -1
    print(ans)



if __name__ == "__main__":
    resolve()

Solution (Python):
N,M,X=map(int, input().split())
a_ls=[[0]*(M+1) for i in range(N)]
for i in range(N):
	a_ls[i]=list(map(int, input().split()))


def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

flag=0
cost=[]

import numpy as np

for i in range(2**N):
	price=0
	target=str(Base_10_to_n(i,2)).zfill(N)
	training=np.array([0]*M)
	for j in range(len(target)):
		if target[j]=="1":
			training=training+np.array(a_ls[j][1:])
			price+=a_ls[j][0]
	
	if sum(training>=np.array([X]*M))==M:
		flag=1
		cost+=[price]


if flag==1:
	print(str(min(cost)))
else:
	print("-1")

Solution (Python):

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

  books = []

  for _ in range(n):
    tpl = tuple(map(int, input().split()))
    books.append((tpl[0], tpl[1:]))

  dp = []

  for c, A in books:
    new_dp = [(c, A)]
    for total_cost, total_amount_list in dp:
      next_list = [A[i] + total_amount_list[i] for i in range(m)]
      new_dp.append((c + total_cost, next_list))

    dp.extend(new_dp)

  ans = tuple(filter(lambda tpl: min(tpl[1]) >= x, dp))
  if len(ans) == 0:
    print(-1)
  else:
    ans = sorted(ans, key=lambda tpl: tpl[0])[0]
    print(ans[0])


main()

Solution (Python):


import itertools

N, M ,X  =  [int(i) for i in input().split()]
Cs = []
for i in range(N):
    Cs.append([int(i) for i in input().split()])


min_a = 10000000000000

for i in range(1, N+1):
    for team in itertools.combinations(Cs, i):
        money = [0] * (M+1)
        for t in team:
            money = [i+j for i,j in zip(money,t)]
        flag = 1
        for m in money[1:]:
            if m < X:
                flag = 0
        if flag == 1 and min_a > money[0]:
            min_a = money[0]
if min_a == 10000000000000:
    print(-1)
else:
    print(min_a)

Solution (Python):



import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf



import math

import bisect

class Book:

    def __init__(self, info):
        self.cost = info[0]
        self.alg = info[1:]


class Solver:

    def __init__(self, books, x, m):
        self.books = books
        
        
        
        
        self.x = x
        self.m = m
        self.cost = 0
        self.skills = []
        self.ans = math.inf

    def run(self):
        for buy_book_bit in range(2 ** 12):
            self.shopping(buy_book_bit)
            if self.check():
                
                
                self.ans = min(self.ans, self.cost)
                
                
        return self.ans

    def check(self):
        for s in self.skills:
            if not (s >= self.x):
                return False
        return True

    def shopping(self, buy_book_bit):
        self.reset()
        for i, book in enumerate(self.books):
            
            
            key = 1 << i
            if key & buy_book_bit:
                self.buy(book)

    def reset(self):
        self.cost = 0
        self.skills = [0] * self.m

    def buy(self, book):
        self.cost += book.cost
        for i, a in enumerate(book.alg):
            self.skills[i] += a





if __name__ == '__main__':
    n, m, x = list(map(int, input().split()))
    books = []
    for i in range(n):
        info = list(map(int, input().split()))
        books.append(Book(info))
    ans = Solver(books, x, m).run()
    
    if ans == math.inf:
        print(-1)
    else:
        print(ans)

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

ans = float('inf')
for i in range(2**n):
    price = 0
    u = [0]*m
    for j in range(n):
        if (i>>j) & 1:
            price += info[j][0]
            for k in range(m):
                u[k] += info[j][k+1]
    ok = True
    
    for l in range(m):
        if u[l] < x:
            ok = False
    if ok:
        ans = min(ans, price)

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

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

c = []
reference = []
for i in range(n):
    price, *a = map(int, input().split())
    c.append(price)
    reference.append(a)

understanding = [0] * m
price = 0
ans = sum(c) + 1

for i in range(2**n):
    understanding = [0] * m
    price = 0
    for j in range(n):
        if (i >> j) & 1:
            price += c[j]
            for k in range(m):
                understanding[k] += reference[j][k]
    
    flg = True
    for j in range(m):
        if understanding[j] < x:
            flg = False
            break
    
    if flg:
        ans = min(ans, price)
        
if sum(c) < ans:
    print(-1)
else:
    print(ans)

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

ichizero=[]
for i in range(2**n):
    kari=[]
    for keta in reversed(range(n)):
        kari.append(i//(2**keta))
        i=i%(2**keta)
    ichizero.append(kari)

mincost=pow(10,7)

for now in ichizero:
    chokudai=[0]*m
    cost=0
    for j in range(n):
        if now[j]==1:
            cost+=kashiko[j][0]
            for k in range(m):
                chokudai[k]+=kashiko[j][k+1]

    if min(chokudai)>=x:
        if mincost>cost:
            mincost=cost

if mincost==pow(10,7):
    ans=-1
else:ans=mincost

print(ans)

Solution (Python):





import sys

def main():
    n, m, x = map(int, sys.stdin.readline().split())
    table = []

    for _ in range(n):
        table.append(list(map(int, sys.stdin.readline().split())))
    for i in range(1, m + 1):
        temp = 0
        for j in range(n):
            temp += table[j][i]
        if temp < x:
            print(-1)
            return
    ans = 0
    for i in range(n):
        ans += table[i][0]
    for i in range(1, 2 ** n):
        temp = i
        cnt = 0
        tempList = [0] * (m + 1)
        while temp > 0:
            if temp % 2:
                for j in range(m + 1):
                    tempList[j] += table[cnt][j]
            temp >>= 1
            cnt += 1
        flag = True
        for j in range(1, m + 1):
            if tempList[j] < x:
                flag = False
                break
        if flag:
            ans = min(ans, tempList[0])
    print(ans)    
    return

if __name__ == "__main__":
    main()

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

n, m, x = map(int, input().split())
ca = np.array([list(map(int, input().split())) for _ in range(n)], dtype="i8")

ans = 10 ** 20
for bit in product([0, 1], repeat=n):
    tmp = np.zeros(m + 1)
    for i, j in enumerate(bit):
        if j == 1:
            tmp += ca[i]
    f = 0
    for i in tmp[1:]:
        if i < x:
            f = 1
    if f == 0:
        ans = min(ans, tmp[0])

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

Solution (Python):
from itertools import combinations

def appliquer(a, cb, n, m, x, c):
	cout = 0
	l = [0]*m
	
	
	
	for i in cb:
		for j in range(m):
			
			l[j]+=a[i][j]
		cout+=c[i]
	
	return cout if all(i>=x for i in l ) else -1

n,m,y = (int(i) for i in input().split())

c = [0]*n
a = []
for i in range(n):
	t = [int(i) for i in input().split()]
	c[i] = t[0]
	a.append(t[1:])
	
rng = [i for i in range(n)]

ans = 100000000

for x in range (1,n+1):
	comb = list(combinations(rng, x))
	for cb in comb:
		cout = appliquer(a, cb, n, m, y, c)
		if cout>=0:
			ans = min(ans, cout)
			
			
print(ans if ans != 100000000 else -1)

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


import itertools
INF = 10 ** 10
ans = INF
for bi in itertools.product([0, 1], repeat=n):
    xx = [0] * m
    cc = 0
    for i, j in enumerate(bi):
        if j == 1:
            for k in range(m):
                xx[k] += ca[i][k+1]
            cc += ca[i][0]
    allok = True
    for i in range(m):
        if xx[i] < x:
            allok = False
    if allok:
        ans = min(ans, cc)
if ans == INF:
    print(-1)
    exit()
print(ans)

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

cnt = float("inf")
for i in range(2**N):
  bs = "0" + format(i,"0{}b".format(N))
  ansl = [0 for _ in range(M+1)]
  for j in range(1,N+1):
    if bs[j] == "1":
      for k in range(M+1):
        ansl[k] += l[j][k]
  
  for j in range(1,M+1):
    if ansl[j] < X:
      break
    if j == M:
      cnt = min(cnt,ansl[0])
if cnt == float("inf"):
  cnt = -1      
print(cnt)

Solution (Python):
def resolve():
    '''
    code here
    '''

    N, M, X = [int(item) for item in input().split()]
    data = [[int(item) for item in input().split()] for _ in range(N)]

    cost = 10**9

    for i in range(2**N):
        temp_point = [0 for _ in range(M)]
        temp_cost = 0
        for j in range(N):
            if ((i >> j) & 1):
                for k, v in enumerate(data[j][1:]):
                    temp_point[k] += v
                temp_cost += data[j][0]

        is_flag = True
        for temp_p in temp_point:
            if temp_p < X:
                is_flag = False
                break
        
        if is_flag:
            cost = min(cost, temp_cost)

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

if __name__ == "__main__":
    resolve()

Solution (Python):
N,M,X=map(int, input().split())
C=[]
A=[]
for i in range(N):
  d=list(map(int, input().split()))
  c1=d[0]
  c2=d[1:]
  C.append(c1)
  A.append(c2)
R=[0]*M
for i in range(N):
  for j in range(M):
    R[j]+=A[i][j]
    
if min(R)<X:
  print(-1)
  exit()

import itertools
D=list(itertools.product([0,1], repeat=N))
ans=(10**5)*12
for i in range(len(D)):
  L=[0]*M
  cnt=0
  for j in range(N):
    cnt+=D[i][j]*C[j]
    for k in range(M):
      L[k]+=D[i][j]*A[j][k]
  if min(L)>=X:
    ans=min(ans,cnt)
print(ans)

Solution (Python):
import math

N,M,X = map(int, input().split())
S = set([tuple([0]*(M+1))])

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

    S2 = set()
    for s in S:
        S2.add(tuple([s[i] + CA[i] for i in range(M+1)]))

    S |= S2

minC = math.inf
for s in S:
    for i in range(M):
        if s[i+1] < X:
            break
    else:
        minC = min(minC, s[0])

if minC == math.inf:
    print(-1)
else:
    print(minC)

Solution (Python):
import numpy as np

N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]
res = float('inf')

def dfs(A):
    global res
    if len(A) == N:
        tmp = np.array([0]*M)
        tmp_c = 0
        for i, a in enumerate(A):
            if a == 1:
                tmp += np.array(books[i][1:])
                tmp_c += books[i][0]

        if np.all(tmp >= X):
            if tmp_c < res:
                res = tmp_c

        return

    dfs(A + [0])
    dfs(A + [1])


dfs([])
if res == float('inf'):
    res = -1
print(res)

Solution (Python):


def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))


N,M,X =  input_multiple_number()

listC = [0]*N
tableA = [[0]*M for i in range(N)]

for i in range(N):
	iii = input_multiple_number_as_list()
	listC[i] = iii[0]
	for j in range(M):
		tableA[i][j] = iii[j+1]
INF = 10000000000
ans = INF

import itertools as it
for i in it.product(range(2), repeat=N):
	isOK = True
	price = 0
	listM = [0]*M
	for j in range(N):
		if i[j] == 1:
			for qqq in range(M):
				listM[qqq] += tableA[j][qqq]
			price += listC[j]
	for skils in range(M):
		isOK = (listM[skils] >= X) and isOK

	if isOK:
		ans = min(price,ans)

if ans == INF:
	print(-1)
else:
	print(ans)

Solution (Python):
import numpy as np

N,M,X = map(int,input().split())
book = [list(map(int,input().split())) for i in range(N)]
npbook = np.array(book)
flag = -1
minsum = 1000000000

for i in range(2**N):
    sumyenskill = np.zeros(M+1)
    for j in range(N):
        if (i>>j)&1 ==1:
            sumyenskill += book[j]

    if min(sumyenskill[1:M+2])>=X:
        flag = 1
        if sumyenskill[0]<minsum:
            minsum = sumyenskill[0]

if flag ==1:
    print(int(minsum))
else:
    print(-1)

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

C = []
A = [ [] for _ in range(N)]
for i in range(N):
    A[i] = [int(x) for x in input().split()]

cost = 10**5 * N
f = False
for i in range(2**N):
    BAG = [0]*(1+M)
    for j in range(N):
        if bin(i>>j)[-1] == '1':
            for k in range(1+M):
                BAG[k] += A[j][k]

    for k in range(1,1+M):
        if BAG[k] < X:
            break
    else:
        f = True
        cost = min(cost,BAG[0])

if f:
    print(cost)
else:
    print(-1)

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

ans = float("inf")

for i in range(2**N):
    l = [0 for _ in range(M)]
    c = 0
    for j in range(N):
        if i >> j & 1:
            l = [x + y for (x, y) in zip(ca[j][1:], l)]
            c += ca[j][0]

    l_bool = [a >= X for a in l]
    if all(l_bool):
        ans = min(ans, c)

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

else:
    print(ans)

Solution (Python):
n,m,x = map(int,input().split())
data = []
a = [0]*n
ans = float('inf')

for i in range(n):
    d = list(map(int,input().split()))
    data.append(d)

def bfs(arrs):
    if len(arrs) == n:
        global ans
        a = [0]*m
        c = 0
        for i in range(n):
            if arrs[i]==1:  
                C = data[i][0]
                A = data[i][1:]
                c += C
                for j in range(m):
                    a[j] += A[j]
        for i in a:
            if i<x:return
        ans = min(ans,c)
    else:
        bfs(arrs + [0])
        bfs(arrs + [1])

bfs([])
if ans == float('inf'):ans=-1
print(ans)

Solution (Python):
import itertools

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

inputs = []
for _ in range(n):
    input_ = map(int, input().split(" "))
    inputs.append(input_)


first = True
min_cost = None
for ui, uses in enumerate(list(itertools.product(*(tuple([[True, False]] * n))))):
    cur_cost = 0
    a_list = [0 for _ in range(m)]
    for i in range(n):
        if uses[i]:
            cur_input = inputs[i]
            c = cur_input[0]
            cur_cost += c
            for ai, a in enumerate(cur_input[1:]):
                a_list[ai] += a


    if first or min_cost > cur_cost:
        count = 0
        ok = True
        for ai, a in enumerate(a_list):
            if a < x:
                ok = False
                break

        if ok:
            first = False
            min_cost = cur_cost

if min_cost is None:
    min_cost = -1
print(min_cost)

Solution (Python):
def main():
    import numpy as np
    n, m, x = map(int, input().split())
    in_lis = []
    for _ in range(n):
        in_lis.append(list(map(int, input().split())))
    
    
    ans = 10 ** 10
    for i in range(1, 2 ** n):
        tmp = 0
        bag = []
        for j in range(n):
            if ((i >> j)& 1):
                bag.append(in_lis[j])
        a = np.array(bag)
        
        sum_retsu = np.sum(a, axis = 0)
        cnt = 0
        
        for k in range(1, m+1):
            if sum_retsu[k] >= x:
                cnt += 1
        if cnt == m:
            tmp = sum_retsu[0]
            ans = min(ans, tmp)
    if ans ==  10 ** 10:
        ans = -1
    print(ans)

    




if __name__ == "__main__":
    main()

Solution (Python):
N,M,X = list(map(int, input().split()))
C = []
A = []
for i in range(N):
  temp = list(map(int, input().split()))
  C.append(temp[0])
  A.append(temp[1:])
moneylist = []
for i in range(2**N):
  Xtemp = []
  moneytemp = 0
  for j in range(M):
    Xtemp.append(0)
  for j in range(N):
    if((i >> j) & 1): 
      for k in range(M):
        Xtemp[k] += A[j][k]
      moneytemp += C[j]
  flag = 0
  for j in range(M):
    if(Xtemp[j] < X):
      flag = 1
      break
  if(flag==0):
    moneylist.append(moneytemp)
  
if(len(moneylist)==0):
  print(-1)
else:
  print(min(moneylist))

Solution (Python):
N, M, X = list(map(int, input().split()))
C_A = [list(map(int, input().split())) for _ in range(N)]
slv_cost = 0
A = [0]*M
for i in range(N):
    slv_cost += C_A[i][0]
    for j in range(M):
        A[j] += C_A[i][j+1] 

for i in range(M):
    if X > A[i]:
        print(-1)
        exit()

for i in range(1, 2**N):
    st = bin(i)[2:][::-1]
    tmp_A = [0]*M
    tmp_cost = 0
    for j in range(len(st)):
        if st[j] == "1":
            tmp_cost += C_A[j][0]
            for l in range(M):
                tmp_A[l] += C_A[j][l+1]
    ok = True
    for j in range(M):
        if X > tmp_A[j]:
            ok = False
    if ok == True:
        slv_cost = min(slv_cost, tmp_cost)
print(slv_cost)

Solution (Python):
N,M,X=map(int,input().split())
arr = []
for i in range(N):
  a = list(map(int,input().split()))
  arr.append(a)

ck = 0
ARR = []
for i in range(2 ** N):
  ans= 0
  bag = [0 for j in range(M)]
  for j in range(N):  
    if ((i >> j) & 1):  
      a = arr[j]
      ans += a[0]
      for k in range(M):
        bag[k] += a[k+1]
  if min(bag) >= X:
    ck = 1
    ARR.append(ans)

if ck == 0:
  print(-1)
else:
  print(min(ARR))

Solution (Python):
INF = 99999999999

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

for _ in range(n):
    a_list = list(map(int, input().split())) 
    c_l.append(a_list[0])
    a_l.append(a_list[1:])

min_c = INF
for i in range(2 ** n):
    bag_c = []
    bag_a = []
    for j in range(n):
        if ((i >> j) & 1):  
            bag_c.append(c_l[j])  
            bag_a.append(a_l[j])
        l = len(bag_a)
        c_sum = 0
        s_sum = [0]*m
        for ii in range(l):
            c_sum += bag_c[ii]
            for mm in range(m):
                s_sum[mm] += bag_a[ii][mm]
        if min(s_sum) >= x and c_sum < min_c:
            min_c = c_sum
if min_c == INF:
    print(-1)
else:   
    print(min_c)

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

ans = 10**9

for i in range(2**n):
    ls = [0] * m
    tmp = 0
    for j in range(n):
        if (i >> j) & 1:
            ls = [l + a for l, a in zip(ls, CA[j][1:])]
            tmp += CA[j][0]
    if all(i >= x for i in ls):
        ans = min(ans, tmp)
print(ans if ans != 10**9 else -1)

Solution (Python):
def main():
    n,m,x = map(int,input().split())
    a = [list(map(int,input().split())) for i in range(n)]
    res = 10**18
    from itertools import product
    for i in product(range(2), repeat=n):
        tmp = 0
        rikai = [0]*m
        okflg = False
        for j in range(n):
            if i[j] == 1:
                tmp += a[j][0]
                okflg = True
                for k in range(1,m+1):
                    rikai[k-1] += a[j][k]
                    if rikai[k-1] < x:
                        okflg = False
                if okflg == True:
                    break
        if okflg == True:
            res = min(tmp,res)
    if res == 10**18:
        print(-1)
    else:
        print(res)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def main():
    N, M, X = map(int, input().split())
    C_A_list = [[int(_) for _ in input().split()] for i in range(N)]

    bit = 1 << N
    INF = float('inf')
    min_price = INF
    for i_bit in range(bit):
        price = 0
        understand_list = [0] * M
        for j_N in range(N):
            if i_bit & (1 << j_N) == 0:
                continue

            price += C_A_list[j_N][0]
            for i, i_A in enumerate(C_A_list[j_N][1:]):
                understand_list[i] += i_A

        for i_understand in understand_list:
            if i_understand < X:
                break
        else:
            min_price = min(min_price, price)

    if min_price == INF:
        print(-1)
    else:
        print(min_price)  

    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Solution (Python):
def study(A,C,m,n,b,x):
    B = [0 for _ in range(m)]
    cost = 0
    for i in range(n):
        if b[i] == "1":
            for j in range(m):
                B[j] += A[i][j]
            cost += C[i]
    if min(B) >= x:
        return (True,cost)
    else:
        return (False,-1)

def pad(b,n):
    if len(b) < n:
        b = "0"*(n-len(b)) + b
    return b

def main():
    N,M,X = map(int,input().split())
    CA = [list(map(int,input().split())) for _ in range(N)]

    C = [CA[i][0] for i in range(N)]
    A = [CA[i][1:] for i in range(N)]

    INF = 12*10**5+1
    ans = INF
    for i in range(2**N):
        b = pad(bin(i)[2:],N)
        st = study(A,C,M,N,b,X)
        if st[0]:
            cost = st[1]
            ans = min(ans,cost)

    if ans < INF:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()

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

text = []
min_money = 100000000
for i in range(N):
  ca = list(map(int,input().split()))
  text.append((ca[0],ca[1:]))
for i in range(2 ** N):
    und = [0]*M
    money = 0
    for j in range(N):  
        if ((i >> j) & 1):  
          und = [x + y for (x, y) in zip(text[j][1], und)]
          money += text[j][0]
    if all([i >= X for i in und]) and money < min_money:
      min_money = money

if min_money == 100000000:
  min_money = -1
print(min_money)

Solution (Python):
mod=1000000007
n,m,x=map(int,input().split())
w=[]
for i in range(n):
    w.append([int(i) for i in input().split()])
ans=mod
for i in range(2**n):
    d=0
    chk=[0]*m
    for j in range(n):
        if (i>>j&1):
            d+=w[j][0]
            for k in range(m):
                chk[k]+=w[j][k+1]

    if min(chk)>=x:
        ans=min(ans,d)

print(ans if ans!=mod else -1)

Solution (Python):



N, M, X = map(int, input().split())
book_list = []
for i in range(N):
    book = list(map(int, input().split()))
    book_list.append(book)


price = float('INF')
is_ok = False


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

for p in pattern:
    tmp_sum = [0]*(M+1)
    is_finish = True
    for i in range(N):
        if p[i]==1:
            for j in range(M+1):
                tmp_sum[j] += book_list[i][j]
    
    for i in range(1, M+1):
        if not tmp_sum[i]>=X:
            is_finish = False
            break

    if is_finish:
        is_ok = True
        price = min(price, tmp_sum[0])


if is_ok:
    print(price)
else:
    print(-1)

Solution (Python):
def dfs(now, l):
    if now == n:
        for ll in l[1:]:
            if ll < x:
                return inf
        return l[0]
    else:
        add_l = []
        for i, j in zip(l, book[now]):
            add = i + j
            add_l.append(add)
        return min(dfs(now + 1, add_l), dfs(now + 1, l))


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

book = []
su = 0
for i in range(n):
    tmp = list(map(int, input().split()))
    su += tmp[0]
    book.append(tmp)

first = [0 for _ in range(m + 1)]
ans = dfs(0, first)
if ans == inf:
    print(-1)
else:
    print(ans)

Solution (Python):
n,m,x = map(int,input().split())
B = [list(map(int,input().split())) for _ in range(n)]
ans = 10**9

for i in range(2**n):
    R = [0 for _ in range(m)]
    tmp = 0
    for j in range(n):
        if i & (1 << j):
            tmp += B[j][0]
            for k,b in enumerate(B[j][1:]):
                R[k] += b
    flag = True
    for r in R:
        if r < x:
            flag = False
            break
    if flag:
        ans = min(ans,tmp)
if ans == 10**9:
    ans = -1
print(ans)

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def print_ans(B):
    for b in B:
        b.sort(key=lambda l: int(l))
        print(" ".join(b))



def main():
    N, M, X = read_values()
    A = read_lists(N)

    res = V(min)
    for i in range(2 ** N):
        K = [0] * (M + 1)
        for n in range(N):
            if i & (1 << n):
                for k in range(M + 1):
                    K[k] += A[n][k]
                
                for k in range(1, M + 1):
                    if K[k] < X:
                        break
                else:
                    res.ud(K[0])

    if res.v is None:
        print(-1)
    else:
        print(res)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import product
import sys

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



combi = list(product('YN', repeat = N))



able = 'No'
ans = sys.maxsize


for i in range(len(combi)):
    
    money = 0
    lx = [0] * M
    for j in range(N):
        
        if(combi[i][j] == 'Y'):
            money += lc[j][0]
            for k in range(M):
                lx[k] += lc[j][k+1]
    
    if(min(lx) >= X):
        
        able = 'Yes'
        ans = min(ans, money)
    

if(able == 'No'):
    print(-1)
else:
    print(ans)

'''
for i in range(len(combi)):
    print(combi[i])
    money = 0
    lx = [0] * M
    for j in range(M):
        if(combi[i][j] == 'Y'):
            money += lc[i][0]
            for k in range(M):
                lx[k] += lc[i][k+1]
            print(money, lx)
'''

Solution (Python):
import itertools

n, m ,x = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = 10**10

for i in itertools.product([0,1], repeat=n):
    c = 0
    b = [0]*m
    for j in range(n):
        if i[j] == 1:
            c += a[j][0]
            for k in range(m):
                b[k] += a[j][k+1]
    for l in range(m):
        if b[l] < x:
            break
    else:
        ans = min(ans, c)
if ans == 10**10:
    print(-1)
else:
    print(ans)

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

ans = []
def read(n,last,*under):
    if n == 0:
        ans.append(list(under))
    else:
        for i in range(last+1, N):
            ui = list(under)
            for m in range(M+1):
                ui[m] += data[i][m]
            read(n-1,i,*ui)

for n in range(1,N+1):
    read(n,-1,*[0]*(M+1))

ans = sorted(ans)
for item in ans:
    flag_m = True
    for m in range(1,M+1):
        if item[m] < X: flag_m = False
    if flag_m:
        print(item[0])
        break

if not flag_m: print(-1)

Solution (Python):
from sys import exit
N, M, X = map(int,input().split())
CA = []
for i in range(N): CA.append(list(map(int,input().split())))
ans = 10 ** 9
for i in range(2 ** N):
    buy = []
    cost = 0
    flag = 0
    for j in range(N):
        if (i >> j) & 1:
            buy.append(CA[j])
    for i in range(M):
        if sum(skill[i + 1] for skill in buy) < X:
            flag = 1
            break
    if flag != 1:
        cost = sum(skill[0] for skill in buy)
        ans = min(ans,cost)
if ans == 10 ** 9: print(-1)
else: print(ans)

Solution (Python):
def main():
    import numpy as np
    from itertools import combinations
    n, m, x = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(n)]

    ans = 10 ** 15
    for i in range(1, n + 1):
        for comb in combinations(l, i):
            y = np.array([x for _ in range(m)])
            tmp = 0
            for p in comb:
                tmp += p[0]
                y -= np.array(p[1:])
            s = sum([j <= 0 for j in y])
            if s == m:
                ans = min(ans, tmp)

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


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import numpy as np

n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
ans = -1
for bool_list in range(2 ** n):
    bool_list = bin(bool_list)[2:].zfill(n)
    cost = 0
    exp = np.array([0] * m)
    for i, b in enumerate(books):
        if bool_list[i] == '1': continue
        cost += b[0]
        tmp = np.array(b[1:])
        exp = exp + tmp
    for y in exp:
        if y < x: break
    else:
        if ans == -1:
            ans = cost
        else:
            ans = min(cost, ans)
print(ans)