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 i in range(n):
  t = list(map(int, input().split()))
  c.append(t[0])
  a.append(t[1:])
ans = 10**10
for s in itertools.product(range(2), repeat=n):
  cost = 0
  skill = [0] * m
  for i in range(n):
    if s[i] == 0:
      continue
    cost += c[i]
    for j in range(m):
      skill[j] += a[i][j]
  if min(skill) >= x:
    ans = min(ans, cost)
if ans == 10**10:
  print(-1)
else:
  print(ans)

Solution (Python):
n,m,x=map(int,input().split())
a=[]
c=[]
ma=[0]*m
for i in range(n):
  cc,*aa=map(int,input().split())
  a.append(aa)
  c.append(cc)
  for j in range(m):ma[j]+=aa[j]
if min(ma)<x:exit(print(-1))
ans=sum(c)
for i in range(1,1<<n):
  f=[0]*m
  cc=0
  for j in range(n):
    if i&(1<<j):
      cc+=c[j]
      for k in range(m):
        f[k]+=a[j][k]
  if min(f)>=x:ans=min(ans,cc)
print(ans)

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


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

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

ans = sys.maxsize

for i in range(1, pow(2, n)):
	s = format(i, 'b')
	bin_str = s.zfill(n)
	
	skills = [0] * m
	price = 0
	
	for j in range(n):
		if bin_str[j] == '1':
			price += books[j][0]
			
			for k in range(1, m + 1):
				skills[k-1] += books[j][k]			
				
	if min(skills) >= x:
		ans = min(ans, price)

if ans == sys.maxsize:
	print(-1)
else:
	print(ans)

Solution (Python):
import itertools

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

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

saisyo = float("inf")
for i in itertools.product(range(2), repeat=N):
    a = [0]*M
    gokei = 0
    for j in range(N):
        if i[j] == 1:
            gokei += A[j][0]
            for k in range(1, M+1):
                a[k-1] += A[j][k]
    if min(a) >= X:
        saisyo = min(saisyo, gokei)

print(saisyo if saisyo != float("inf") else -1)

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

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

    min_total_cost = 10**9

    for i in range(2**N):
        total_cost = 0
        learned = [0] * M

        for j in range(N):
            if (i >> j) & 1:
                cost, *points = books[j]
                total_cost += cost

                learned = [x + y for x, y in zip(learned, points)]

        if min(learned) >= X:
            min_total_cost = min(min_total_cost, total_cost)

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


if __name__ == "__main__":
    main()

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


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

    books = np.array([list(map(int, input().split())) for _ in range(N)])

    min_total_cost = 10**9

    for read_flags in product((True, False), repeat=N):
        to_read_books = books[read_flags, :]
        total_cost = to_read_books[:, 0].sum()
        increased_levels = to_read_books[:, 1:].sum(axis=0)

        if min(increased_levels) >= X:
            min_total_cost = min(min_total_cost, total_cost)

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


if __name__ == "__main__":
    main()

Solution (Python):



N,M,X=map(int,input().split(" "))
array=[]
_INF_ = 1001001001
ans = _INF_
for i in range(N):
     H = input().rstrip()
     array.append(H.split(" "))


for i in range(1<<N): 
    cost = 0
    understand = [0 for un in range(M)]
    
    for j in range(N):
        if(((i>>j)&1)): 
            ar = array[j][0]
            cost+=int(ar)
            for un in range(M):
                a1 = array[j][un+1]
                understand[un]+=int(a1)
        ok = True
    for un in range(M):
        if understand[un]<X:
            ok = False
    if ok:
        ans = min(ans, cost)
        
        
if(ans == _INF_):
    print(-1)
else:
    print(ans)

Solution (Python):
candidates = []

def get_candidate(indices, current, num):
  global candidates

  if len(current) == num:
    candidates.append(current.copy())
    return
  
  for i, v in enumerate(indices):
    current.append(v)
    get_candidate(indices[i+1:], current, num)
    current.pop()
  
n, m, x = list(map(lambda x: int(x), input().split(' ')))
books = []

for i in range(0, n):
  p = list(map(lambda x: int(x), input().split(' ')))
  books.append((p[0], p[1:]))

indices = list(range(0, n))

for i in range(1, n+1):
  get_candidate(indices, [], i)

flag = False
min_price = 1000000000

for c in candidates:
  price = 0
  a = [0] * m
  
  for s in c:
    price += books[s][0]

    for i in range(m):
      a[i] += books[s][1][i]

  for t in a:
    if t < x:
      flag = True
      break

  if flag:
    flag = False
    continue
  
  min_price = min(min_price, price)

if min_price == 1000000000:
  print("-1") 
else:
  print(min_price)

Solution (Python):
import math
N , M , X =  map(int,input().split())
A = {}
B = {}
ANS = 100000000000
for i in range(1,N+1):
    A[i]=list(map(int,input().split()))
for i in range(1,2**N):
    l = str(bin(i))
    n = len(l)
    ans=0
    for s in range(1,M+1):
        B[s]=0
    for k in range(1,n+1):
        if l[-k] == "1":
            ans = ans + A[k][0]
            for s in range(1,M+1):
                B[s] += A[k][s]
    if all((B[l] >= X for l in range(1,M+1))):
        ANS = min(ans,ANS)
if ANS == 100000000000:
    print("-1")
else:
    print(ANS)

Solution (Python):
import numpy as np

_,*_t=[list(map(int,i.split())) for i in open(0)]
n=_[0]
m=_[1]
x=_[2]
table=np.array(_t)
value=9000000


def boolAchieve(nums):
  for i in range(1,m+1):
    if nums[i]<x:
      return False
  return True

  
def makeBoolList(nums):
  ls=[]
  sNums=str(nums)
  for i in range(len(sNums)):
    if sNums[i]=="0":
      ls.append(False)
    else:
      ls.append(True)
  return ls


tmp=np.sum(table,axis=0)
if not boolAchieve(tmp):
  print(-1)
  exit()


for i in range(1,2 ** n):
  row=format(i,'b').zfill(n)
  selects=makeBoolList(row)
  picks=np.sum(table[selects,:],axis=0)
  if not boolAchieve(picks):
    continue
  value=min(value,picks[0])

  
print(value)

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):
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]

final = 1000000000

for i in range(1, 2**N):
    ans = 0
    rikai = [0]*M
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(1, M+1):
                rikai[k-1] += A[j][k]
            ans += A[j][0]
    if all(el >= X for el in rikai):
        final = min(final, ans)

if final == 1000000000:
    print(-1)
else:
    print(final)

Solution (Python):
N, M, X = map(int, input().split(" "))
book_information = []
result = 12 * 10**5 + 1
for i in range(N):
	book_information.append(input())
for i in range(1, 1 << N):
  bought_book = []
  n = 0
  cost = 0
  skill = [0 for j in range(M)]
  for j in range(N):
    if (i >> j) & 1:
      bought_book.append(book_information[j])
      n += 1
  for j in range(n):
    bought_book_information = list(bought_book[j].split(" "))
    cost += int(bought_book_information[0])
    for k in range(M):
      skill[k] += int(bought_book_information[k + 1])
  if all(x >= X for x in skill):
    result = min(result, cost)
if result == 12 * 10**5 + 1:
  print(-1)
else:
  print(result)

Solution (Python):
from itertools import product
 
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")
for i in product(range(2),repeat=N):
    ans1=0
    l=[0 for i in range(M)]
    for j in range(N):
        if i[j]==1:
            ans1+=A[j][0]
            for k in range(M):
                l[k]+=A[j][k+1]
    if min(l)>=X:
        ans=min(ans,ans1)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

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

for i in range(n+1):
    toBuyc=list(itertools.combinations(C,i))
    for j in range(len(toBuyc)):
    
        pattern.append(toBuyc[j])
   
"""for i in range(2**n):
    toBuy=[]
    for j in range(n):
        if ((i>>j)&1):
            toBuy.append(C[j])"""
   
    

X=[0]*m 
xsum=0
sum=0
min=12000000 
check=0
for tb in pattern:
    sum=0
    xsum=0
    X=[0]*m
    for c in tb:
        for j in range(len(c)):
            if j==0:
                sum+=c[j]
            else:
                xsum+=c[j]
                X[j-1]+=c[j]
    if xsum<x*m:
        continue
    else:
        for eX in X:
            if eX<x:
                check=1
        if check==1:
            check=0
            continue
        if sum<min:
            min=sum
if min==12000000:
    print(-1)
else:
    print(min)

Solution (Python):
from sys import maxsize
import numpy as np


def check(ls, x):
    for i in range(1, len(ls)):
        if ls[i] < x:
            return False
    return True


n, m, x = map(int, input().split())
ls = []
a = [i for i in range(n)]
for i in range(n):
    ls.append(list(map(int, input().split())))
dp = [np.zeros(m + 1) for i in range((1 << n))]
for i in range(n):
    dp[1 << i] = np.array(ls[i])
total_cost = maxsize
for subset in range(1, (1 << n)):
    for i in range(n):
        if subset & (1 << i):
            dp[subset] = np.add(dp[subset ^ (1 << i)], dp[(1 << i)])
    if check(dp[subset], x):
        total_cost = min(total_cost, dp[subset][0])
if total_cost == maxsize:
    print(-1)
else:
    print(int(total_cost))

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

cost_0 = 10000000
b = f"0{N}b"
for i in range(2**N):
    i_bit = str(format(i,b))
    
    Ans = [0]*(M+1)
    for j in range(N):
        if i_bit[j] == "1":
            Ans = [p+ca for p,ca in zip(Ans,CA[j])]
    if min(Ans[1:])>=X:
        cost = Ans[0]
    else:
        cost = cost_0
    cost_0 = min(cost_0,cost)
if cost_0 != 10000000:
    print(cost_0)
else:
    print(-1)

Solution (Python):
def saiki(N,M,X,check,book,cost):
	if len(check) == N:
		u = [0] * M
		c = 0
		for i in range(N):
			if check[i] == 1:
				b = book[i]
				c += b[0]
				for j in range(1,M+1):
					u[j-1] += b[j]
		if min(u) >= X:
			if cost[0] == -1 or cost[0] > c:
				cost[0] = c
	else:
		C = check[:]
		saiki(N,M,X,C+[0],book,cost)
		C = check[:]
		saiki(N,M,X,C+[1],book,cost)

if __name__ == '__main__':
	N,M,X = map(int, input().split())
	book = []
	for _ in range(N):
		book.append([int(a) for a in input().split()])

	cost = [-1]
	saiki(N,M,X,[],book,cost)

	print(cost[-1])

Solution (Python):

from itertools import product


def main():
    N, M, X, *CA = map(int, open(0).read().split())
    conditions = tuple(zip(*[iter(CA)] * (M + 1)))
    ans = 1 << 30
    for p in product(range(2), repeat=N):
        cur = [0] * (M + 1)
        for is_available, condition in zip(p, conditions):
            if not is_available:
                continue
            for i, (x, y) in enumerate(zip(cur, condition)):
                cur[i] = x + y
        if all(i >= X for i in cur[1:]):
            ans = min(ans, cur[0])
    print(ans if ans != 1 << 30 else -1)


if __name__ == "__main__":
    main()

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

total = float('inf')
ok = False
for pr in product([0, 1], repeat=n):
    clct = 0
    for a in zip(*A):
        cnt = 0
        for i in range(n):
            if pr[i] == 1:
                cnt += a[i]
        if cnt >= x:
            clct += 1
    
    if clct == m:
        ok = True
        ttl = 0
        for c,p in zip(C, pr):
            if p == 1:
                ttl += c
        total = min(total, ttl)

if ok:
    print(total)
else:
    print(-1)

Solution (Python):
import itertools
n,m,x=map(int,input().split())
lis=tuple(tuple(map(int,input().split())) for _ in range(n))
ans=float("inf")

def dfs(progress,skills,nowcost):
    global ans
    if progress==n:
        if all(v>=x for v in skills):
            ans=min(ans,nowcost)
        return ans
    dfs(progress+1,skills,nowcost)
    dfs(progress+1,[a+b for a,b in zip(skills,lis[progress][1:])],nowcost+lis[progress][0])

dfs(0,[0]*m,0)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Solution (Python):
n,m,x = map(int,input().split())
c = []
bit = 0
for i in range(n):
    c.append(list(map(int,input().split())))
ans = 1000000000000
for i in range(2**n):
    l = [0 for _ in range(m)]
    current = 0
    for j in range(n):
        if (i>>j)&1:
            current += c[j][0]
            for k in range(m):
                l[k] += c[j][k+1]
    flag = 1
    for h in l:
        if h < x:
            flag = 0
    if flag:
        ans = min(ans,current)
if ans == 1000000000000:
    print(-1)
else:
    print(ans)

Solution (Python):
import numpy as np
import itertools
N,M,X=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(N)]
ans=9999999999
 
V=list(itertools.product([0,1], repeat=N))
 
for v in V:
  cost=0
  C=[0]*M
  for n in range(N):
    if v[n]==1:
      cost += arr[n][0]
      for j in range(1,M+1):
        C[j-1] += arr[n][j]
      
  if min(C) >= X:
    ans=min(ans,cost)
    
if  ans ==  9999999999: 
  print(-1)
else:
  print(ans)

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(cost_sum,ans)
if ans == INF:
    print(-1)
else:
    print(ans)

Solution (Python):
n,m,x=map(int,input().split())
C=[]
for i in range(n):
    a=list(map(int,input().split()))
    C.append(a)
pattern=[]
toBuy=[]
for i in range(2**n):
    toBuy=[]
    for j in range(n):
        if ((i>>j)&1):
            toBuy.append(C[j])
 
    pattern.append(toBuy)

X=[0]*m 
xsum=0
sum=0
min=12000000 
check=0
for tb in pattern:
    sum=0
    xsum=0
    X=[0]*m
    for c in tb:
        for j in range(len(c)):
            if j==0:
                sum+=c[j]
            else:
                xsum+=c[j]
                X[j-1]+=c[j]
    if xsum<x*m:
        continue
    else:
        for eX in X:
            if eX<x:
                check=1
        if check==1:
            check=0
            continue
        if sum<min:
            min=sum
if min==12000000:
    print(-1)
else:
    print(min)

Solution (Python):
import itertools
n,m,x=map(int,input().split())
lis=tuple(tuple(map(int,input().split())) for _ in range(n)) 
ans=float("inf")

def dfs(progress,skills,nowcost):
    global ans
    if progress==n:
        if all(v>=x for v in skills):
            ans=min(ans,nowcost)
        return 0
    dfs(progress+1,skills,nowcost)
    dfs(progress+1,[a+b for a,b in zip(skills,lis[progress][1:])],nowcost+lis[progress][0])

dfs(0,[0]*m,0)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

Solution (Python):
from itertools import product

N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")

for now in product(range(2), repeat=N):
    res = 0
    An = [0 for _ in range(M)]
    for n in range(N):
        if now[n] == 1:
            res += A[n][0]
            An = [An[j] + A[n][j+1] for j in range(M)]
    if min(An) >= X:
        ans = min(ans, res)

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

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

for i in range(2**N):
  cost=0
  C=[0]*M
  for n in range(N):
    
    if (i>>n) &1:
      cost += arr[n][0]
      for j in range(1,M+1):
        C[j-1] += arr[n][j]
  if min(C)>=X:
    ans=min(ans, cost)
    
if ans ==  9999999999:
  print(-1)
else:
  print(ans)

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

matrix = []
c = []
ans = float("inf")

for i in range(N):
    matrix.append(list(map(int, input().split())))
    c.append(matrix[i].pop(0))

for i in range(2 ** N):
    cost = 0
    rikai = [0] * M
    for j in range(N):
        if ((i >> j) & 1):
            cost += c[j]
            for k in range(M):
                rikai[k] += matrix[j][k]
    flg = True
    for k in range(M):
        if rikai[k] < X:
            flg = False
    if flg:
        ans = min(ans, cost)
    

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

Solution (Python):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")



def main():
    N, M, X = map(int, input().split())
    CA_list = [list(map(int,list(input().split(" ")))) for i in range(N)]
    Ci_sum_list = []
    
    for i in range(2 ** N):
        sum_list = [0 for i in range(M + 1)]
        for j in range(N):
            if ((i >> j) & 1):
                sum_list = [x + y for (x, y) in  zip(sum_list, CA_list[j])]
                
        logging.info(sum_list)
        if [x for x in sum_list[1:] if x < X]:
            continue
        else:
            Ci_sum_list.append(sum_list[0])

    if Ci_sum_list:
        print(min(Ci_sum_list))
    else:
        print(-1)
        
if __name__ == "__main__":
    main()

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

ans = float('inf')
def dfs(step, m_list, cost):
    global ans
    if all(elem>=x for elem in m_list):
        ans = min(cost, ans)
    elif step != n:
        dfs(step+1, m_list, cost)
        m_list = [x+y for x, y in zip(m_list, a[step][1:])]
        cost += a[step][0]
        dfs(step+1, m_list, cost)

dfs(0, [0]*m, 0)
print(-1 if ans==float('inf') else ans)

Solution (Python):
def check(learn_total):
    for i in range(m):
        if learn_total[i] < x:
            return False
    return True


def calc_price(bit):
    price_total = 0  
    learn_total = [0] * m  

    for i in range(n):
        if (bit >> i) & 1:  
            price_total += c[i]  
            learn = a[i]  
            for j, le in enumerate(learn):  
                learn_total[j] += le

    
    if check(learn_total):
        return price_total
    else:
        return INF


if __name__ == '__main__':
    INF = float("inf")

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

    
    c = []  
    a = []  

    for i in range(n):
        c_temp, *a_temp = list(map(int, input().split()))  
        c.append(c_temp)
        a.append(a_temp)

    ans = INF

    for bit in range(1 << n):
        price = calc_price(bit)  
        ans = min(ans, price)  

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

Solution (Python):
def check(learn_total):
    for i in range(m):
        if learn_total[i] < x:
            return False
    return True


def calc_price(bit):
    price_total = 0  
    learn_total = [0] * m  

    for i in range(n):
        if (bit >> i) & 1:  
            price_total += c[i]  
            learn = a[i]  
            for j, le in enumerate(learn):  
                learn_total[j] += le

    
    if check(learn_total):
        return price_total
    else:
        return INF


if __name__ == '__main__':
    INF = float("inf")

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

    
    c = []  
    a = []  

    for i in range(n):
        c_temp, *a_temp = list(map(int, input().split()))  
        c.append(c_temp)
        a.append(a_temp)

    ans = INF

    for bit in range(1 << n):
        price = calc_price(bit)  
        ans = min(ans, price)  

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

Solution (Python):
N, M, X = map(int, input().split())
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
min = -1
for i in range(1, 2**N):
  x = []
  for j in range(M):
    x.append(0)
  c = 0
  chk = True
  for j in range(N):
    b = bin(i & 2**j)
    if b[2] == "1":
      c += A[j][0]
      for k in range(M):
        x[k] += A[j][k+1]
  for l in range(M):
    if x[l] < X:
      chk = False
      break
  if chk == False:
    continue
  if min == -1:
    min = c
  elif c < min:
    min = c
print(min)

Solution (Python):
from itertools import product as pr
n,m,x=[int(i) for i in input().split()]
l=[[int(i) for i in input().split()]for j in range(n)]
p=list(pr([0,1],repeat=n))
suml=[[sum([l[j][k]*i[j] for j in range(n)])for k in range(m+1)]for i in p]
ans=[i[0] for i in suml if all([i[j] >=x for j in range(1,m+1)])]
if len(ans)==0:
  print(-1)
else:
  print(min(ans))

Solution (Python):
import numpy as np

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

ans = float('inf')
for i in range(2 ** n):
    cost = 0
    exp = np.array([0] * m)
    for j , b in enumerate(books):
        if i >> j & 1: continue
        cost += b[0]
        exp = exp + np.array(b[1:])
    if (exp < x).any(): continue
    ans = min(cost, ans)

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

Solution (Python):
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
ans = float("INF")

for i in range(1 << n):
    costs = 0
    understand = [0] * m
    for j in range(n):
        if i >> j & 1:
            costs += c[j][0]
            for k in range(m):
                understand[k] += c[j][k + 1]
    if min(understand) >= x:
        ans = min(ans, costs)
    
print(ans) if ans != float("INF") else print(-1)

Solution (Python):
import itertools
n,m,x=map(int,input().split())
lis=tuple(tuple(map(int,input().split())) for _ in range(n)) 
ans=float("inf")

for choice in itertools.product(range(2),repeat=n):
    cost=0
    skills=[0]*m
    for flag,book in zip(choice,lis):
        if flag:
            C,A = book[0],book[1:]
            cost += book[0]
            for i,a in enumerate(A):
                skills[i]+=a
    if all(v>=x for v in skills):
        ans=min(ans,cost)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

Solution (Python):
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
ans = float("INF")

for i in range(1 << n):
    costs = 0
    understand = [0] * m
    for j in range(n):
        if i >> j & 1:
            costs += c[j][0]
            for k in range(m):
                understand[k] += c[j][k + 1]
    if min(understand) >= x:
        ans = min(ans, costs)
    
print(ans) if ans != float("INF") else print(-1)

Solution (Python):
n,m,x=map(int,input().split())
cam = [list(map(int, input().split())) for i in range(n)]
ans=10000**12

for i in range(2**n):
    a=[0]*m
    cst=0
    for j in range(n):
        bag=[]
        if (i>>j)&1:
            cst+=cam[j][0]
            for k in range(1,m+1):
                a[k-1]+=cam[j][k]
    if all(elem >= x for elem in a):
        ans=min(ans,cst)
    
if ans<10000**12:
    print(ans)
else:
    print(-1)

Solution (Python):
n,m,x = map(int, input().split())
books = [[*map(int, input().split())] for _ in range(n)]
ans = inf = 10**18
for bit in range(1<<n): 
    cost = 0
    skill = [0]*m
    for book in range(n): 
        if(bit>>book & 1): 
            cost += books[book][0] 
            skill = [*map(lambda x,y: x+y, skill, books[book][1:])] 
    if min(skill) >= x: ans = min(ans, cost) 
if ans == inf: ans = -1 
print(ans)

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

ans = float('inf')
exist = False
for bit in range(1 << N):
    flag = True
    S = [0]*M
    sumnum = 0
    for i in range(N):
        if bit & (1 << i):
            sumnum += C[i]
            for j in range(M):
                S[j] += A[i][j]

    for k in range(M):
        if S[k] < X:
            flag = False
            break
    if flag:
        ans = min(ans, sumnum)
    
if ans != float('inf'):
    print(ans)
else:
    print(-1)

Solution (Python):
n,m,x = map(int, input().split())
books = [[*map(int, input().split())] for _ in range(n)]
ans = inf = 10**18
for bit in range(1<<n): 
    cost = 0
    skill = [0]*m
    for book in range(n): 
        if(bit>>book & 1): 
            cost += books[book][0]
            for j in range(m): skill[j] += books[book][j+1] 
    if min(skill) >= x: ans = min(ans, cost)
if ans == inf: ans = -1
print(ans)

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

import numpy as np

A=[]
B=[]

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


C=[]
temp=[0 for i in range(N)]

for i in range(2**N):
  for j in range(N):
    if (i >> j) & 1:
      temp[j]=1
    else:
      temp[j]=0
  tempE=[0 for i in range(M+1)]
  for k in range(N):
    x = np.array(tempE)
    y = np.array([A[k][j]*temp[k] for j in range(M+1)])
    tempE=x+y
  C.append(tempE)


tempC=float('inf')
for i in range(2**N):
  tempD=min(C[i][1:M+1])
  if tempD>=X:
    tempC=min([tempC,C[i][0]])

if tempC==float('inf'):
  tempC=-1

print(tempC)

Solution (Python):
import itertools

n, m, x = map(int, input().split())
book = [list(map(int, input().split())) for i in range(n)]
count = 0
min_total=100000000

for i in range(2 ** n):
    subtotal = 0
    tmp_rikaido=[0]*m
    for j in range(n):
        if (i >> j) & 1:
            subtotal+=book[j][0]
            for k in range(m):
                tmp_rikaido[k] += book[j][k + 1]
                if all(a >= x for a in tmp_rikaido):
                    count += 1
                    if min_total > subtotal:
                        min_total=subtotal

if count == 0:
    print(-1)
else:
    print(min_total)

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

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

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books)


  if N == 1:
    if np.all(books[:, 1:] >= X):
      print(books[0][0])
    else:
      print(-1)
    return True
  books_index_pattarns = [list(x) for i in range(1, N+1) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)]

  if len(books_result) == 0:
    print(-1)
    return True
  elif len(books_result) == 1:
    print(books_result[0][0])
    return True
  else:
    
    print(books_result[:,:1].min())
    return True

if __name__ == "__main__":
    resolve()

Solution (Python):
n,m,x = map(int, input().split())
c = [0]*n
a = [[]]*n
for i in range(n):
    d = [*map(int, input().split())]
    c[i] = d[0]
    a[i] = d[1:]
ans = inf = 10**18

for bit in range(1<<n): 
    cost = 0
    skill = [0]*m
    for book in range(n): 
        if(bit>>book & 1): 
            cost += c[book]
            for j in range(m): skill[j] += a[book][j] 
    if min(skill) >= x: ans = min(ans, cost)
if ans == inf: ans = -1
print(ans)

Solution (Python):

































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

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

s = float('inf')
r = False

for i in range(2 ** N):
    _s = 0
    t = [0 for _ in range(M)]
    for k in range(N):
        if (i >> k & 1):
            _s += L[k][0]
            for j in range(M):
                t[j] += L[k][j + 1]
    _r = True
    for _t in t:
        if _t < X:
            _r = False
            break
    if _r and _s < s:
        r = True
        s = _s
if r:
    print(s)
else:
    print(-1)

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

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

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M+1):
  if sums[i] < X:
    OK = False
    break

if OK == False:
  print(-1)
else:
  As = []
  for A in combinations_with_replacement(range(0, N),N):
    As.append(tuple(set(A)))
  As = list(map(list, set(As)))
  min_ = sums[0]
  for i in As:
    mini_CA = []
    for j in i:
      mini_CA.append(CA[j])
    mini_CA = np.array(mini_CA)
    OK2 = True
    sums = np.sum(mini_CA,axis=0)
    for k in range(1,M+1):
      if sums[k] < X:
        OK2 = False
        break
    if OK2 == True and sums[0] < min_:
      min_ = sums[0]
  print(min_)

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

c = [0]*n
a = [[]]*n

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


ans = inf = 10**18

for bit in range(1<<n): 
    cost = 0
    skill = [0]*m
    for book in range(n): 
        
        if(bit>>book & 1): 
            cost += c[book]
            for j in range(m):
                skill[j] += a[book][j] 
    
    

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

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