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 itertools

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

ans = -1
for cart in itertools.product([True, False], repeat=n):
    price = 0
    score = [0] * m
    for ni in range(n):
        if cart[ni]:
            price += c[ni]
            for mi in range(m):
                score[mi] += a[ni][mi]
    score_check = True
    for mi in range(m):
        if score[mi] < x:
            score_check = False
            break
    if score_check:
        if ans == -1:
            ans = price
        else:
            ans = min(ans, price)

print(ans)

Solution (Python):
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

import sys
import numpy as np

sys.setrecursionlimit(10**8)
n,m,x=mi()
list_ans=[]
for i in range(n):
  c_=lmi()
  list_ans.append(c_)

ans=float('inf')

def dfs(i,suma,count):
  global ans
  if i==n:
    
    if np.all(count>=x):
      ans=min(ans,suma)
      return ans

  else:
    dfs(i+1,suma,count)
    dfs(i+1,suma+list_ans[i][0],count+np.array(list_ans[i][1:]))

dfs(0,0,np.array([0]*m))
if ans==float('inf'):
  print(-1)
  exit()
  
else:
  print(ans)

Solution (Python):
import math
N, M, X = map(int, input().split())
C = []
A = []
for i in range(N):
  l = list(map(int, input().split()))
  C.append(l[0])
  A.append(l[1:])
  
ans = math.inf
for i in range(2**N):
  a = [0]*M
  c = 0
  flag = True
  for j in range(N):
    if ((i >> j) & 1):
      a = list(map(sum, zip(a, A[j-1])))
      c += C[j-1]
  for x in a:
    if x < X:
      flag = False
      break
  if flag:
    ans = min(ans, c)
    
if ans == math.inf:
  ans = -1
print(ans)

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

for i in range(2**n):
  bin(i)
  d=[0 for _ in range(m+1)]
  
  for j in range(n):
    if ((i >> j) & 1):
      for k in range(m+1):
        d[k]+=c[j][k]
        
  for j in range(m):
    if d[j+1] <x:
      break
  else:
    if sm>d[0] or sm==-1:
      sm=d[0]
      
print(sm)

Solution (Python):
import sys
import numpy as np
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
  
n,m,x = Mi()
a = []
b=[0]*m
b = np.array(b)
for i in range(n):
  a.append(Li())
  
ans = 10**7
def DFS(cost,start,skill):
  global ans
  if min(skill) >= x:
    ans = min(ans,cost)
    return ans
  for i in range(start,n):
    DFS(cost+a[i][0],i+1,skill+np.array(a[i][1:]))
  return ans

a = DFS(0,0,b)
if a == 10**7:
  a = -1
print(a)

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

(n, m, x), cost = map(int, input().split()), sys.maxsize
s = [list(map(int, input().split())) for i in range(n)]
for i in range(1, 1 << n):
    k, y = [0 for i in range(m)], 0
    for j in range(n):
        if (i >> j) & 1:
            for ii in range(1, m + 1): k[ii-1] += s[j][ii]
            y += s[j][0]
    if all([k[j] >= x for j in range(m)]): cost = min(cost, y)
print(-1 if cost == sys.maxsize else cost)

Solution (Python):


import sys
stdin = sys.stdin
from itertools import product
import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, x = na()
    c, a = list(), list()
    for i in range(n):
        ci, *ai = na()
        c.append(ci)
        a.append(ai)
    a = np.array(a)
    buy_book = product([0,1], repeat=n)
    ans = 10**10
    f = False
    for book_list in buy_book:
        cost = 0
        b = [0] * m
        for book, ci, ai in zip(book_list, c, a):
            if book==1:
                cost += ci
                b += ai
        if np.min(b) >= x:
            f = True
            ans = min(ans, cost)
    print(ans if f else -1)



if __name__ == "__main__":
    main()

Solution (Python):

N, M, X = 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):
    t = [0] * M
    c = 0
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)

Solution (Python):
Max = 100000000
N, M, X = map(int, input().split())
A = []
for j in range(N):
	A.append(list(map(int, input().split())))

R = 2**N
ans = Max
for i in range(R):
	cost = 0
	check = M*[0]
	
	for j in range(N):
		if (i>>j)&1:
			cost += A[j][0]
			for k in range(M):
				check[k] += A[j][k+1]

	judge = 1
	for j in range(M):
		if  check[j] < X:
			judge = 0
			break
	if judge==1:
		ans = min(ans, cost)

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

Solution (Python):
import numpy as np

N, M, X = map(int, input().split())
ca_list = [list(map(int, input().split())) for _ in range(N)]
c = [ca_list[i][0] for i in range(N)]
a = [ca_list[i][1:] for i in range(N)]

a = np.array(a)
cost = 1000000000000000000

for i in range(1, 2 ** N):
    skill = np.zeros((1, M))
    money = 0
    for j in range(N):
        if (i >> j) & 1:
            skill += a[j]
            money += c[j]

    if np.all(skill >= X):
        cost = min(cost, money)

if cost == 1000000000000000000:
    cost = -1

print(cost)

Solution (Python):
import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

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

    ans = 10**10

    for i in range(2 ** n):
        skill = [0]*m
        cost = 0
        for j in range(n):  
            if ((i >> j) & 1):
                cost += l[j][0]
                for k in range(m):
                    skill[k] += l[j][k+1]
        if all(skill[i] >= x for i in range(m)):
            ans = min(ans, cost)

    print(ans if ans != 10**10 else -1)


resolve()

Solution (Python):

 
from itertools import combinations
 
 

def main():
    N, M, X = map(int, input().split())
    CA = [[] for _ in range(N)]
    for n in range(N):
        CA[n] = list(map(int, input().split()))
 
    COSTS = []
    for n in range(N):
        for c in combinations(CA, n+1):
            SUM = [0 for _ in range(M)]
            COST = 0
            for ca in c:
                COST += ca[0]
                for m in range(M):
                    SUM[m] += ca[m+1]
            if all(list(map(lambda x: x >= X, SUM))):
                COSTS.append(COST)
    if COSTS:
        print(min(COSTS))
        return
    print(-1)
 
if __name__ == '__main__':
    main()

Solution (Python):
n,m,x = map(int,input().split())
c=[]
for i in range(n):
  a=[int(i) for i in input().split()]
  c.append(a)
import numpy as np
c=np.array(c)
ans=float('inf')
for i in range(1,2**n):
  p=[0]*m
  cost=0
  for j in range(n):
    if(i>>j)&1==1:
      cost+=c[j][0]
      p+=c[j][1:]
    if min(p)>=x:
      ans=min(ans,cost)
       
if ans==float('inf'):
  ans=-1
print(ans)

Solution (Python):
import numpy as np
n,m,x = map(int,input().split())
c = []
for i in range(n):
  a = [int(i) for i in input().split()]
  c.append(a)
  
c = np.array(c)
ans = float('inf')
for i in range(1,2**n):
  chk = [0]*m
  cost = 0
  for j in range(n):
    if (i>>j)&1 == 1:
      cost += c[j][0]
      chk += c[j][1:]
  if min(chk) >= x:
    ans = min(ans,cost)
  
if ans == float('inf'):
  ans = -1
print(ans)

Solution (Python):

n,m,x = map(int,input().split())
a = []
c = []
for s in range(n):
	c_tmp,*a_tmp = list(map(int,input().split()))
	c.append(c_tmp)
	a.append(a_tmp)

c_ans = []
for i in range(2**n):
	ans_box = [0]*m
	c_box = 0
	for j in range(n):
		if(i>>j)&1 == 1:
			for p in range(m):
				ans_box[p] += a[j][p]
			c_box += c[j]
	if min(ans_box) >= x:
		c_ans.append(c_box)

print(min(c_ans) if len(c_ans)>0 else -1)

Solution (Python):

n,m,x = map(int,input().split())
a = []
c = []
for s in range(n):
	c_tmp,*a_tmp = list(map(int,input().split()))
	c.append(c_tmp)
	a.append(a_tmp)

c_ans = []
for i in range(2**n):
	ans_box = [0]*m
	c_box = 0
	for j in range(n):
		if(i>>j)&1 == 1:
			for p in range(m):
				ans_box[p] += a[j][p]
			c_box += c[j]
	if min(ans_box) >= x:
		c_ans.append(c_box)

print(min(c_ans) if len(c_ans)>0 else -1)

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

for i in range(1,2**n) :
    a = format(i,"b")
    a = a.zfill(n)
    ans = [0]*(m+1)
    for j in range(n) :
        if a[j] == "1" :
            ans = list(map(lambda s,t: s+t, ans , ca[j]))
    l = 0
    for k in range(1,m+1) :
        if ans[k] >= x :
            l += 1
    if l == m :
        money.append(ans[0])

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

Solution (Python):
import numpy as np
N, M, X = map(int, input().split())
A = []
C = []
for _ in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)
A = np.array(A,dtype=int)
ans = 10 ** 7
for bit in range(2 ** N):
    B = np.zeros(M, dtype=int)
    cost = 0
    for i in range(N):
        if bit & (1<<i):
            B += A[i]
            cost += C[i]
    if np.all(B >= X):
        ans = min(ans, cost)
print(ans if ans < 10**7 else -1)

Solution (Python):
from sys import stdin
a = stdin.readlines()

n = int(a[0].split()[0])
m = int(a[0].split()[1])
x = int(a[0].split()[2])

l = []
for i in range(n):
    tmp = []
    for j in range(m+1):
        tmp.append(int(a[i+1].split()[j]))
    l.append(tmp)

ans = []
for i in range(2**n):
    bag = []
    for j in range(n):
        if ((i >> j) & 1):
            bag.append(l[j])
    s = [0]*(m+1)
    for j in range(len(bag)):
        s = list(map(lambda x,y: x+y, s, bag[j]))
    for j in range(1,m+1):
        if not s[j] >= x:
            break
    else:
        ans.append(s[0])
if ans == []:
    print(-1)
else:
    print(min(ans))

Solution (Python):
import itertools

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

ans = 10**8

for i in range(2**N):
    score = [0] * M
    total = 0
    for j in range(N):
        if ((i >> j) & 1):
            total += a[j][0]
            for k in range(M):
                score[k] += a[j][k+1]
        
    if min(score) >= X:
        ans = min(ans, total)

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

Solution (Python):
import itertools

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



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


ans=100000000
for L in Ls:
    
    cost=0
    rikai=[0]*(M+1)
    hon=0
    flag=0
    for l in L:
        
        if l==1:  
            cost+=CA[hon][0]
            
            for i in range(1,M+1):
                rikai[i]+=CA[hon][i]
            

        hon+=1

    
    
    for i in range(1,M+1):
        if rikai[i]<X:  
            flag=1
    
    if flag==0:  
        ans=min(ans,cost)
    else:  
        continue
if ans==100000000:
    print(-1)
else:
    print(ans)

Solution (Python):
import numpy as np

n,m,x=map(int, input().split())
sl=[]
pl=[]
for k in range(n):
  book=list(map(int,input().split()))
  sl.append(book[1:])
  pl.append(book[0])
  
sl=np.array(sl)
ans=10**8

for i in range(2**n):
  skill=np.zeros(m)
  price=0
  for j in range (n):
    if ((i>>j)&1):
      skill+=sl[j]
      price+=pl[j]
  bottom=np.amin(skill)
  if bottom>=x and price<ans:
    ans=price
if ans==10**8:
  print(-1)
else:
  print(ans)

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

def dfs(i, ais, cur):
	if i == len(ais): return 0 if all([e<=0 for e in cur]) else +float('inf')
	return min( ais[i][0] + dfs(i+1 , ais, [c - ais[i][j+1] for j,c in enumerate(cur)]), dfs(i+1, ais, cur))

r = dfs(0,ais,[x] * m) 
print r if r < float('inf') else -1

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

ans=float('inf')

for i in range(1<<n):
    cost_sun=0
    rikaido=[0]*m
    for j in range(n):
        if(i>>j)&1:
            cost_sun+=c[j]
            for k in range(m):
                rikaido[k]+=a[j][k]
    
    isOK=True
    for j in range(m):
        if rikaido[j]<x:
            isOK=False
            break
    if isOK:
        ans=min(ans, cost_sun)

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

Solution (Python):
n, m, x = map(int, input().split())
lst = []
for i in range(n):
  lst.append(list(map(int, input().split())))
pmin = 10 ** 10
for i in range(1, 2 ** n): 
  sbin = format(i, 'b')
  sbin = '0' * (n - len(sbin)) + sbin
  temp = [0] * m
  p = 0
  for j in range(n): 
    if sbin[j] == '1':
      for k in range(m): 
        temp[k] += lst[j][k + 1]
      p += lst[j][0]
  if min(temp) >= x:
    pmin = min(pmin, p)
if pmin == 10 ** 10:
  print(-1)
else:
  print(pmin)

Solution (Python):
import numpy as np

n,m,x=map(int,input().split())
c=[]
a=[]
ans=10**8

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

a=np.array(a)


for i in range(2**n):
  level=np.zeros(m)
  price=0
  for j in range(n):
    if ((i>>j)&1):
      level+=a[j]
      price+=c[j]
  bottom=int(np.amin(level))
  if bottom>=x and price<ans:
    ans=price
if ans==10**8:
  print(-1)
else:
  print(ans)

Solution (Python):
N, M, X = map(int, input().split())
c_list = []
a_list = []
for i in range(N):
    tmp = list(map(int, input().split()))
    c_list.append(tmp.pop(0))
    a_list.append(tmp)

cost = 100000000000
flg = False
for cnt in range(2 ** N):
    cost_tmp = 0
    score_tmp = [0] * M
    cnt_str = format(cnt, 'b')
    cnt_str = cnt_str[::-1]
    
    for i in range(len(cnt_str)):
        if(cnt_str[i] == '1'):
            cost_tmp += c_list[i]
            for j in range(M):
                score_tmp[j] += a_list[i][j]
    if(sum(x >= X for x in score_tmp) == M):
        cost = min(cost, cost_tmp)
        flg = True

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

Solution (Python):
import numpy as np

n,m,x=map(int,input().split())
c=[]
a=[]
ans=10**8

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

a=np.array(a)


for i in range(2**n):
  level=np.zeros(m)
  price=0
  for j in range(n):
    if ((i>>j)&1):
      level+=a[j]
      price+=c[j]
  bottom=int(np.amin(level))
  if bottom>=x and price<ans:
    ans=price
if ans==10**8:
  print(-1)
else:
  print(ans)

Solution (Python):
import numpy as np

N, M, X = map(int, input().split())
CA = np.array([list(map(int, input().split())) for _ in range(N)], dtype=int)
C = CA[:, 0]
A = CA[:, 1:]

def is_ok(mask):
    if not np.any(mask):
        return False
    return np.all(np.sum(A[mask], axis=0)>=X)

ans = np.inf
for bit_mask in range(2**N):
    mask = [bool((bit_mask >> i) & 1) for i in range(N)]
    if is_ok(mask):
        ans = min(ans, sum(C[mask]))
print(ans if ans!=np.inf else -1)

Solution (Python):

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

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

ans = 10**10
for bit in range(1<<N):
    sum_p = 0
    p = [ 0 for _ in range(M) ]
    for i in range(N):
        if bit & 1<<i:
            for j, a in enumerate(A[i]):
                p[j] = p[j] + a
            sum_p = sum_p + C[i]

    n = sum( x >= X for x in p )
    if n == M:
        ans = min(ans, sum_p)

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

Solution (Python):
N,M,X = map(int,input().split())
C = []
A = []
for n in range(N):
    l = list(map(int,input().split()))
    C.append(l[0])
    A.append(l[1:len(l)])
l = [0] * (N + 1)
Mx = 10 ** 7
Mn = Mx
while True:
    i = 0
    while True:
        l[i] = l[i] ^ 1
        if l[i] == 1:
            break
        i += 1
    if i >= N:
        break
    lA = [0] * M
    c = 0
    for n in range(N):
        if l[n] == 0:
            continue
        c += C[n]
        for m in range(M):
            lA[m] += A[n][m]
    flg = True
    for m in range(M):
        if lA[m] < X:
            flg = False
            break
    if not flg:
        continue
    if c < Mn:
        Mn = c
if Mn == Mx:
    print(-1)
else:
    print(Mn)

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

for i in range(2**n):
    l = [0]*m
    h = 0
    for j in range(n):
        if ((i >> j) & 1):
            for p in range(m):
                l[p] += list_CA[j][p+1]
            h += list_CA[j][0]
    cnt = 0
    for k in l:
        if k >= x:
            cnt += 1
    if cnt == m:
        ans = min(ans, h)

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

Solution (Python):
n,m,x=map(int,input().split())
book_list=[list(map(int,input().split())) for _ in range(n)]
ans=-1
for i in range(2**n):
    result=[0]*(m+1)
    for j in range(n):
        if (i>>j)&1:
            for k in range(m+1):
              result[k]+=book_list[j][k]
    if min(result[1:m+1])>=x:
      if ans==-1:
        ans=result[0]
      else:
        ans=min(ans,result[0])
print(ans)

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

ans = []
s = [0 for i in range(2 ** n)]
for i in range(2 ** n):
    tmp_0 = [0]
    tmp_1 = [0 for i in range(m)]
    for j in range(n):
        if ((i >> j) & 1):
            tmp_0[0] += a[j][0]
            for k in range(1,m+1):
                tmp_1[k-1] += a[j][k]
    
    if min(tmp_1) >= x:
        ans.append(tmp_0[0])

if not ans:
    print(-1)
else:
    print(min(ans))

Solution (Python):
n,m,x=map(int,input().split())
book_list=[list(map(int,input().split())) for _ in range(n)]
ans=-1
for i in range(2**n):
    result=[0]*(m+1)
    for j in range(n):
        if (i>>j)&1:
            for k in range(m+1):
              result[k]+=book_list[j][k]
    if min(result[1:m+1])>=x:
      if ans==-1:
        ans=result[0]
      else:
        ans=min(ans,result[0])
print(ans)

Solution (Python):
N, M, X = list(map(int, input().split()))
ca_list = [list(map(int, input().split())) for _ in range(N)]
c = [ca_list[i][0] for i in range(N)]
a = [ca_list[i][1:] for i in range(N)]
ans = sum(c)
check = False

for i in range(2**N):
    total = 0
    skills = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            total += c[j]
            skills = [k + l for k, l in zip(a[j], skills)]
    if all([z >= X for z in skills]):
        ans = min(total, ans)
        check = True

if check:
    print(ans)
else:
    print(-1)

Solution (Python):

"""
Created on Mon Jun 29 06:00:56 2020

@author: Aruto Hosaka
"""


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







P = [row[0] for row in C]
A = [row[1:M+1] for row in C]

K = [0 for i in range(2**N)]
G = [[0 for k in range(M)] for i in range(2**N)]
for i in range(2**N):
    i2 = format(i, '012b')
    s = 0
    for k in range(N):
        K[i] += int(i2[11-k])*P[k]
        for j in range(M):
            G[i][j] += int(i2[11-k])*A[k][j]

J = [[K[i],G[i]] for i in range(2**N)]
J = sorted(J)

t = 0
for i in range(2**N):
    for j in range(M):
        if (J[i][1])[j] < X:
            break
        if j == M-1:
            t = 1
            print(J[i][0])
    if t== 1:
        break

if t==0:
    print(-1)

Solution (Python):
N , M , X = map(int,input().split())
CA_list = [list(map(int,input().split())) for _ in range(N)]
c = [CA_list[i][0] for i in range(N)]
a = [CA_list[i][1:] for i in range(N)]

cost = sum(c)
ans = 0


for i in range(2**N):
   temp = 0
   skill = [0] * M
   
   for j in range(N):
     if (i >> j) & 1:
        temp += c[j] 
        skill = [y + z for (y,z) in zip(skill,a[j])]
   if all([z >= X for z in skill ]):
        cost= min(cost,temp)
        ans += 1
        
if ans == 0:
    print(-1)
else:
    print(cost)

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

ans = float('inf')
for bit in range(1 << N):
    book = [0]*M
    cost = 0
    for i in range(N):
        if(bit >> i) & 1:
            cost += CA[i][0]
            for c in range(M):
                book[c] += (CA[i][c+1])

    if all(X <= a for a in book):
        ans = min(ans,cost)
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 i in range(N)]

ans = float('inf')
for bit in range(1 << N):
    book = [0]*M
    cost = 0
    for i in range(N):
        if(bit >> i) & 1:
            cost += CA[i][0]
            for c in range(M):
                book[c] += (CA[i][c+1])

    if all(X <= a for a in book):
        ans = min(ans,cost)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
N, M, X = map(int, input().split())
A = []
C = []
for _ in range(N):
    c, *a = list(map(int, input().split()))
    A.append(a)
    C.append(c)
ans = float("inf")
for b in range(2**N):
    param = [0]*M
    tmp = 0
    for i in range(N):
        if 1&(b>>i):
            tmp += C[i]
            param = list(map(lambda a,b: a+b, A[i], param))
    if all([x>=X for x in param]):
        ans = min(tmp, ans)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')




import numpy as np


def solve():
    N, M, X = MI()
    C = []
    A = []
    for i in range(N):
        tmp = LI()
        C.append(tmp[0])
        A.append(np.array(tmp[1:]))

    ans = INF
    for i in range(1 << N):
        bag = []
        for j in range(N):
            if (i >> j) & 1:
                bag.append(j)
        sm = np.zeros(M)
        c = 0
        for b in bag:
            c = c + C[b]
            a = A[b]
            sm = sm + a
        if np.all(sm >= X):
            ans = min(ans, c)

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





if __name__ == '__main__':
    solve()

Solution (Python):
n, m, x = map(int, input().split())
c, a = [], []
for i in range(n):
  tmp = [int(j) for j in input().split()]
  c.append(tmp[0])
  a.append(tmp[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 = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 193934993409409

for mask in range(2 ** n):
    C = [0] * m
    cost = 0

    for i in range(n):
        if (mask >> i) & 1:
            cost += X[i][0]
            
            
            

            for j in range(1, m + 1):
                C[j - 1] += X[i][j]
    
    if min(C) >= x:
        ans = min(ans, cost)

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

Solution (Python):
n,m,x=map(int, input().split())
C, A = [], []
for i in range(n):
	c, *a = map(int, input().split())
	C.append(c)
	A.append(a)


cost=0


flg=False
ans=sum(C)
for i in range(1,2**n):
	
	X=[0]*m
	cost=0
	flg=True
	
	for j in range(n):
		if (i>>j)&1 == 1:
			cost += C[j]
			for k in range(m):
				X[k] += A[j][k]
	for idx in X:
		if idx < x:
			flg = False
			break
	
	
	
	
	if flg:
		ans = min(ans,cost)

if flg:
	print(ans)
else:
	print('-1')

Solution (Python):
import itertools
import numpy as np

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

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

A = np.array(A)
C = np.array(C)

answer = 10**9
for comb in itertools.product([0, 1], repeat= N):
    cost = 0
    A_memo = np.zeros(M, dtype=int)

    for i in range(N):
        if not comb[i]:
            continue

        A_memo += A[i]
        cost += C[i]

    if (A_memo >= X).sum() == M:
        answer = min(answer, cost)

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

Solution (Python):
def solve():
    N,M,X = map(int,input().split())
    C = []
    A = []
    for _ in range(N):
        CA = list(map(int,input().split()))
        C.append(CA[0])
        A.append(CA[1:])
    
    ans = float('inf')
    for i in range(1<<N):
        cost_sum = 0
        power = [0] * M
        for j in range(N):
            if (i >> j) & 1:
                cost_sum += C[j]
                for k in range(M):
                    power[k] += A[j][k]
        
        isOk = True
        for j in range(M):
            if power[j] < X:
                isOk = False
                break
        
        if isOk:
            ans = min(ans, cost_sum)
    
    print(ans if ans != float('inf') else -1)
        
if __name__ == '__main__':
    solve()

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

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

minprice = 1<<34
canComp = False
for i in itertools.product([0, 1], repeat=N):
    ok = True
    known = [0] * M
    price = 0
    for n, j in enumerate(i):
        if j == 1:
            book = books[n]
            price += book[0]
            for a, know in enumerate(book[1:]):
                known[a] += know

    for know in known:
        if know < X:
            ok = False
            break
    if ok:
        canComp = True
        minprice = min(minprice, price)
    
if canComp:
    print(minprice)
else:
    print(-1)

Solution (Python):









import os
import sys
from itertools import combinations
import numpy as np



def main():
    n, m, x = map(int, input().split())
    s = []
    for i in range(n):
        s.append(list(map(int, input().split())))
    s = np.array(s)
    total = 100000000


    for i in range(1, n+1):
        for lili in list(combinations(range(n), i)):
            s_list = np.zeros((m+1), dtype=np.int32)
            for li in lili:
                s_list += s[li]

            if (s_list[1:] >= x).all() and s_list[0] < total:
                total = s_list[0]
    if total == 100000000:
        print(-1)
    else:
        print(total)


if __name__ == "__main__":
    main()

Solution (Python):
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
p = float("inf")

for i in range(1, 2 ** n):
    s = [0] * m
    count = 0
    ps = 0
    for j in range(n):
        if (i >> j) & 1:
            ps += a[j][0]
            for k in range(m):
                s[k] += a[j][k + 1]

    for k in range(m):
        if s[k] >= x:
            count += 1

    if count == m:
        p = min(ps, p)

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

Solution (Python):
from collections import defaultdict as dd
from collections import deque
from itertools import combinations as combination
import bisect
import heapq

def ri():
    return int(input())

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

def subset(A):
    for l in range(len(A) + 1):
        for comb in combination(A, l):
            yield comb

def solve():
    n, m, x = rl()
    C = []
    A = []
    for i in range(n):
        line = rl()
        C.append(line[0])
        A.append(line[1:])

    min_cost = 10**20
    for sub in subset(range(n)):
        skills = [0] * m
        cost = 0
        for s in sub:
            for i in range(m):
                skills[i] += A[s][i]
            cost += C[s]

        for skill in skills:
            if skill < x:
                break
        else:
            min_cost = min(min_cost, cost)

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






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

Solution (Python):
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
p = float("inf")

for i in range(1, 2**n):
    s = [0]*m
    count = 0
    ps = 0
    for j in range(n):
        if (i >> j) & 1:
            ps += a[j][0]
            for k in range(m):
                s[k] += a[j][k+1]
                
    for k in range(m):
        if s[k] >= x:
            count += 1
            
    if count == m:
        p = min(ps, p)
        
if p == float('inf'):
    print(-1)
else:
    print(p)

Solution (Python):
n,m,x=map(int,input().split())
C=[[] for i in range(n)]
for i in range(n):
  A=list(map(int,input().split()))
  C[i]=[A[0],A[1:]]
  
  
cost=float("inf")
for bit in range(1<<n):
  
  for i in range(m):
    if sum([C[j][1][i] for j in range(n) if bit>>j & 1 ])<x:
      break
  else:
    cost=min(cost, sum([C[j][0] for j in range(n) if bit>>j & 1 ]))
    
print(cost if cost<float("inf") else -1)