Problem:
 Score : 300 points    Problem Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0 .  Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i -th book ( 1\leq i\leq N ) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j -th algorithm will increase by A_{i,j} for each j ( 1\leq j\leq M ).
There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.      Constraints  All values in input are integers.  1\leq N, M\leq 12  1\leq X\leq 10^5  1\leq C_i \leq 10^5  0\leq A_{i, j} \leq 10^5         Input Input is given from Standard Input in the following format:  N  M  X  C_1  A_{1,1}  A_{1,2}  \cdots  A_{1,M}  C_2  A_{2,1}  A_{2,2}  \cdots  A_{2,M}  \vdots  C_N  A_{N,1}  A_{N,2}  \cdots  A_{N,M}       Output If the objective is not achievable, print -1 ; otherwise, print the minimum amount of money needed to achieve it.        Sample Input 1 3 3 10
60 2 2 4
70 8 7 9
50 2 3 9      Sample Output 1 120  Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.       Sample Input 2 3 3 10
100 3 1 4
100 1 5 9
100 2 6 5      Sample Output 2 -1  Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.       Sample Input 3 8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2      Sample Output 3 1067

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

def skill_up(bit,m,x,c,a):

    acc_m = 10**9 + 1

    for can,acc_u in aaa(bit,m,x,c,a):
        if can < acc_m and all([s >= x for s in acc_u]):
            acc_m = can
    if acc_m > 10**9:
        return -1
    else:
        return acc_m

def aaa(bit,m,x,c,a):
    mx = 2**bit
    for i in range(1,mx):
        acc_u = [0] * m
        can = 0
        for b in range(bit):
            r = i & (1 << b)
            
            if r != 0:
                v = int(math.log2(r))
                
                for j in range(m):
                    acc_u[j] += a[v][j]
                can += c[v]
        
        
        yield can,acc_u

if __name__ == "__main__":
    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:])

    
    print(skill_up(n,m,x,c,a))

Solution (Python):
import sys
input = sys.stdin.readline
import math
def bit_check(n,m,x,c,a):
    mx = 2**n
    bit = n
    acc_m = 10**9 + 1


    for i in range(1,mx):
        acc_u = [0] * m
        can = 0
        for b in range(bit):
            r = i & (1 << b)
            
            if r != 0:
                v = int(math.log2(r))
                
                for j in range(m):
                    acc_u[j] += a[v][j]
                can += c[v]
        
        
        if can < acc_m and all([s >= x for s in acc_u]):
            acc_m = can
    if acc_m > 10**9:
        return -1
    else:
        return acc_m
    
if __name__ == "__main__":
    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:])

    print(bit_check(n,m,x,c,a))

Solution (Python):
n, m, x = map(int, input().split())
bl = []
for i in range(n):
  b = list(map(int, input().split()))
  bl.append(b)
ans = 10 ** 8


for i in range(1<<n):
  c = 0
  
  
  u = [x] * m
  
  for j in range(n):
    
    if i & 1<<j:
      b = bl[j]
      c += b[0]
      for k in range(1, m+1):
        u[k-1] -= b[k]
  
  if max(u) <= 0:
    ans = min(ans, c)


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

Solution (Python):
import sys
from copy import deepcopy
def main():
    INF=sys.maxsize
    N,M,X=tuple(map(int,sys.stdin.readline().split()))
    B=[]
    for _ in [0]*N:B.append([int(x) for x in sys.stdin.readline().split()])
    T=[0 for _ in range(M+1)]
    T[0]=INF
    for p in range(1,2**N):
        TT=[0 for _ in range(M+1)]
        for i in range(N):
            f=(p>>i)&1
            if f>0:TT=list(map(lambda x:x[0]+x[1],zip(TT,B[i])))
        F=list(map(lambda x:x>=X,TT[1:]))
        
        if TT[0]<T[0] and all(F):T=TT
    print(T[0]) if T[0]!=INF else print('-1')
if __name__=='__main__':main()

Solution (Python):
N,M,X = map(int,input().split())
C = [0] * N
A = [None] * N
for i in range(N):
  c,*a = map(int,input().split())
  C[i] = c
  A[i] = a

INF = 10 ** 9
ans = INF
import itertools
for i in range(2 ** N):
  cost = 0
  skills = [0] * M
  for j in range(N):
    if (i >> j) & 1:
      cost += C[j]
      for k in range(M):
        skills[k] += A[j][k]
    if cost >= ans:
      continue
    for s in skills:
      if s < X:
        break
    else:
      ans = cost

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

Solution (Python):
N,M,X = map(int,input().split())
C = [0] * N
A = [None] * N
for i in range(N):
  c,*a = map(int,input().split())
  C[i] = c
  A[i] = a

INF = 10 ** 9
ans = INF
import itertools
for i in range(1,N + 1):
  for comb in itertools.combinations(range(N),i):
    cost = 0
    skills = [0] * M
    for c in comb:
      cost += C[c]
      for j in range(M):
        skills[j] += A[c][j]
    if cost >= ans:
      continue
    for s in skills:
      if s < X:
        break
    else:
      ans = cost

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

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

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

costs = np.zeros(N, dtype=int)
up = np.zeros((N, M), dtype=int)
for i in range(N):
  l = list(map(int, input().split()))
  costs[i] = l[0]
  up[i, :] = l[1:]




b = [[False, True]] * N
min_cost = np.inf

for p in product(*b):
  
  p = list(p)
  case_cost = np.sum(costs[p])
  case_up = np.sum(up[p, :], axis=0)
  if (case_up >= X).all() and min_cost > case_cost:
    min_cost = case_cost
if min_cost == np.inf:
  print(-1)
else:
  print(min_cost)

Solution (Python):
N,M,X=map(int,input().split())
C=[]
As=[]
for _ in range(N):
  c,*a=map(int,input().split())
  C+=[c]
  As+=[a]
r=1e9
for i in range(2**N):
  cost=0
  perf=[0]*M
  for j in range(N):
    if (i>>j)&1:
      cost+=C[j]
      perf=[perf[k]+As[j][k] for k in range(M)]
  if all(p>=X for p in perf):
    r=min(r,cost)
if r==1e9:r=-1
print(r)

Solution (Python):
def solve():
    N, M, X = map(int, input().split())
    ans = 1000000000
    C = [0 for _ in range(N)]
    A = [[0 for _ in range(M)] for _ in range(N)]
    for j in range(N):
        C[j], *A[j] = map(int, input().split())

    for i in range(2 ** N):
        tmp = 0
        algorithm = [0 for _ in range(M)]
        for j in range(N):
            if (i >> j) & 1:
                for k in range(M):
                    algorithm[k] += A[j][k]
                tmp += C[j]
        if min(algorithm) >= X:
            ans = min(ans, tmp)

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
















if __name__ == '__main__':
    solve()

Solution (Python):
import itertools
 
N, M, X = (int(v) for v in input().split())
c = [0]*N
a = [0]*N
 
for i in range(N):
    items = [int(v) for v in input().split()]
    c[i] = items[0]
    a[i] = items[1:]


coin = list(itertools.product([0,1], repeat=N))
ans_cost = -1

for i in range(len(coin)):
    score = [0] * M
    for j in range(N):
        if coin[i][j] == 1:
            for k in range(M):
                score[k] += a[j][k]
    if min(score) >= X:
        cost = 0
        for l in range(N):
            cost += coin[i][l] * c[l]
        if (ans_cost == -1) | (cost < ans_cost):
            ans_cost = cost

print(ans_cost)

Solution (Python):
import sys
from itertools import product

import numpy as np

N, M, X = map(int, input().split(' '))
books = np.fromiter(sys.stdin.read().split(), dtype=int).reshape((N, M + 1))
indexes = np.arange(0, N, dtype=int)

min_cost = 10 ** 9
for bool_indexes in product((False, True), repeat=N):
    bool_indexes = list(bool_indexes)
    if np.min(np.sum(books[indexes[bool_indexes], 1:], axis=0)) >= X:
        min_cost = min(min_cost, books[indexes[bool_indexes], 0].sum())

if min_cost == 10 ** 9:
    min_cost = -1

print(min_cost)

Solution (Python):
import itertools

N, M, X = (int(v) for v in input().split())
c = [0]*N
a = [0]*N

for i in range(N):
    items = [int(v) for v in input().split()]
    c[i] = items[0]
    a[i] = items[1:]

coin = list(itertools.product([0,1], repeat=N))
ans_cost = -1

for i in range(len(coin)):
    score = [0] * M
    for j in range(N):
        if coin[i][j] == 1:
            for k in range(M):
                score[k] += a[j][k]
    if min(score) >= X:
        cost = 0
        for l in range(N):
            cost += coin[i][l] * c[l]
        if (ans_cost == -1) | (cost < ans_cost):
            ans_cost = cost

print(ans_cost)

Solution (Python):
n,m,x = map(int,input().split())
c = []
for i in range(n):
    ci = list(map(int,input().split()))
    c.append(ci)
t = [0 for i in range(m+1)]
def dfs(l,i):
    if i == n:
        if min(l[1:]) >= x:
            return l[0]
        else:
            return 10**9
    d = l[:]
    for j in range(m+1):
        d[j] += c[i][j]
    return min(dfs(l,i+1),dfs(d,i+1))
ans = dfs(t,0)
if ans == 10**9:
    print(-1)
    exit()
print(ans)

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

ans = []
for i in range(2**n):
    v = i

    c_sum = 0
    a = [0 for _ in range(m)]
    for j in range(n):
        if v % 2 == 0:
            c_sum += cA[j][0]
            for k in range(m):
                a[k] += cA[j][k + 1]
        v //= 2

    if min(a) >= x:
        ans += [c_sum]

if len(ans) == 0:
    print(-1)
else:
    print(sorted(ans)[0])

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, 2 ** 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):
N,M,X = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
table = [0]*M
ans = 10**9+7
cnt = 0
for bit in range(1<<N):
    table = [0]*M
    cnt = 0
    B = [(bit>>i)&1 for i in range(N)]
    for j in range(N):
        if B[j] == 1:
            for k in range(M):
                table[k] += A[j][k+1]
            cnt += A[j][0]
    if min(table) >= X:
        ans = min(ans,cnt)
if ans == 10**9+7:
    ans = -1
print(ans)

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

Solution (Python):
N, M, X = map(int, input().split())
cost = []
cont = []
INF = float('inf')
for _ in range(N):
    C, *A = map(int, input().split())
    cost.append(C)
    cont.append(A)
    
def calc(bit):
    price = 0
    skill = [0]*M
    for i in range(N):
        if (bit >> i) & 1:
            price += cost[i]
            for j, la in enumerate(cont[i]):
                skill[j] += la
    if min(skill) >= X:
        return price
    else:
        return INF
    
ans = INF
for bit in range(1 << N):
    price = calc(bit)
    ans = min(ans, price)
if ans == INF:
    print(-1)
else:
    print(ans)

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):
n,m,x=map(int,input().split(" "))
c=[]
a=[]
for i in range(n):
    tmp=[int(i) for i in input().split(" ")]
    c.append(tmp[0])
    a.append([])
    for j in range(m):
        a[i].append(tmp[j+1])
ans=int(1e9)
for mask in range(1<<n):
    w=[0]*m
    cost=0
    for i in range(n):
        if (mask>>i)&1:
            for j in range(m):
                w[j]+=a[i][j]
            cost+=c[i]
    ok=True
    for j in range(m):
        if w[j]<x:
            ok=False
    if ok:
        ans=min(ans,cost)
if ans==int(1e9):
    print("-1")
else:
    print(ans)

Solution (Python):

import numpy as np
import math
from itertools import combinations
N,M,X=list(map(int,input().split()))
book_dict={}
for i in range(N):
    book_dict[i] = list(map(int,input().split()))

answer = (10**5*12)+1
for i in range(N,0,-1):
    current_book_number=0    
    for v in combinations(book_dict.keys(), i):
        
        search_book = list(map(lambda x:book_dict[x],list(v)))
        sum_search_book = np.array(np.sum(search_book,axis = 0))
        if (np.count_nonzero(sum_search_book[1:] >= X) == M) and sum_search_book[0] < answer:
            answer = sum_search_book[0]
        else:
            current_book_number+=1
    
    if current_book_number==int(math.factorial(N)/(math.factorial(i)*math.factorial(N-i))):
        break                                                                                 
    
if answer == (10**5*12)+1:
    answer = -1

print(answer)

Solution (Python):

import numpy as np
from itertools import combinations
N,M,X=list(map(int,input().split()))
book_dict={}
for i in range(N):
    book_dict[i] = list(map(int,input().split()))

answer = (10**5*12)+1
for i in range(N,0,-1):
    for v in combinations(book_dict.keys(), i):
        search_book = list(map(lambda x:book_dict[x],list(v)))
        sum_search_book = np.array(np.sum(search_book,axis = 0))
        if (np.count_nonzero(sum_search_book[1:] >= X) == M) and sum_search_book[0] < answer:
            answer = sum_search_book[0]
                                                                                 
    
if answer == (10**5*12)+1:
    answer = -1

print(answer)

Solution (Python):
[n, m, x], *t = [[*map(int, t.split())] for t in open(0)]
ans = 1200001
for i in range(1, 2**n):
    tmp = [t[k] for k in range(n) if 1 << k & i]
    c, *a = map(sum, zip(*tmp))
    if min(a) >= x:
        ans = min(ans, c)
if ans == 1200001:
    print(-1)
else:
    print(ans)

Solution (Python):

import numpy as np

N, M, X = list(map(int, input().split()))
C = []
A = np.zeros((N, M), dtype=int)

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

result = -1
for i in range(1 << N):
    reading_books = np.zeros((M), dtype=int)
    cost = 0
    for j in range(N):
        if not (i >> j) & 1:
            continue
        cost += C[j]
        reading_books += A[j, :]
    if all(reading_books >= X):
        if result == -1:
            result = cost
        else:
            result = min(cost, result)


print(result)

Solution (Python):
import itertools
import numpy as np

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


result = -1
anp = np.array(a)
sum = sum(c)


    
for i in itertools.product([0,1],repeat=n):
    each_cost =0
    ans =anp.T*i


    if min(ans.sum(axis=1))>=x:
        sum = min(np.dot(c,i),sum)
        result = 0



if result ==0:
    print(sum)
else:
    print(-1)

Solution (Python):
import numpy as np 
from itertools import combinations
N,M,X = (int(x) for x in input().split())
C =np.zeros(N,dtype=int)

A =np.zeros((N,M),dtype=int)
for i in range(N):
    x,*y = (int(x) for x in input().split())
    C[i] =x
    A[i] =np.array(y,dtype=int)


ans =[]
for i in range(1,N+1): 
    for j in combinations(range(N),i): 
        understanding =np.sum(A[j,],axis=0)
        if np.all(understanding >=X):
            z =np.sum(C[j,])
            ans.append(z)
        
        
if len(ans) >0:
    print(min(ans))
else:
    print(-1)

Solution (Python):
N,M,X =map(int,input().split())
A =[]
for m in range(N):
    A.append([int(j) for j in input().split()])
ans = 10**10
import numpy as np
from itertools import product,compress
for i in list(product([True,False],repeat=N)):
    tmp = np.sum(list(compress(A, i)),axis=0)
    if type(tmp)!=np.float64:
    	if tmp[0]< ans and min(tmp[1:])>=X:
            ans =tmp[0]
if ans ==10**10:
    print(-1)
else:
    print(ans)

Solution (Python):
def f(p):
    bp=bin(p)[2:].zfill(n)
    tmp=[x]+[0 for _ in range(m)]
    cost=0
    for i in range(n):
        if bp[i]=="0": continue
        cost+=skill[i][0]
        for j in range(1,m+1):
            tmp[j]+=skill[i][j]
    return cost if min(tmp)>=x else 10**15

n,m,x=map(int,input().split())
skill=[list(map(int,input().split())) for _ in range(n)]
ans=10**15
for p in range(2**n):
    ans=min(ans,f(p))
print(ans if ans<10**15 else -1)

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

costl = []

for p in itertools.product([0,1],repeat=N):
    f = [0]*M
    cost = 0
    for i in range(N):
        if p[i] == 1:
            for j in range(M):
                f[j] += arr[i][j+1]
            cost += arr[i][0]
    if all(point >= X for point in f):
        costl.append(cost)

print(min(costl) if len(costl) >= 1 else -1)

Solution (Python):
N,M,X = map(int, input().split())
C = [0]*N
A = [[[0]*M] for i in range(N)]
for i in range(N):
    C[i], *A[i] = map(int, input().split())
MAX = 10**5 * 12 + 1
minprice = MAX
for b in range(2**N):
    abilityList = [0]*M
    price = 0
    for i in range(N):
        if b >> i & 1 == 1:
            abilityList = [x+y for (x,y) in zip(abilityList, A[i])]
            price += C[i]
    judge = True
    for ability in abilityList:
        if ability < X:
            judge = False
    if judge:
        minprice = min(minprice, price)
ans = minprice if minprice != MAX else -1
print(ans)

Solution (Python):
def main():
  
  

  
  

  f_inf=float("inf")
  
  
  if 'get_ipython' in globals(): 
    
    n, m, x = 3, 3, 10
    C = [60, 70, 50]
    A = [[2, 2, 4], [8, 7, 9], [2, 3, 9]] 

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

  
  ans = f_inf
  for s in range(1<<n): 
    cost = 0
    D = [0] * m
    for i in range(n):
        if s>>i & 1: 
            cost += C[i]
            for j in range(m):
                D[j] += A[i][j]
    
    flg = True
    for d in D:
        if d < x: flg = False
    if flg: ans = min(ans, cost)

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

main()

Solution (Python):
n,m,x=map(int,input().split())
book=[0]*n
for i in range(0,n):
  book[i]=list(map(int,input().split()))
total=[]
for i in range(2**n):
  cost=0
  rikai=[0]*m
  for j in range(n):
    if (i >> j)&1:
      for k in range(m):
        rikai[k] += book[j][k+1]
      cost+=book[j][0]
  if all(l >= x for l in rikai):
    total.append(cost)

if total==[]:
  print("-1")
else:
  print(min(total))

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):
import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline

N, M, X, *CA = map(int, read().split())
CA = tuple(zip(*[iter(CA)] * (M + 1)))
answer = 10 ** 10
for i in product((0, 1), repeat=N):
    m = 0
    s = [0] * M
    for j in range(N):
        if i[j] == 1:
            m += CA[j][0]
            for k in range(M):
                s[k] += CA[j][k + 1]
    if all(j >= X for j in s):
        if answer > m:
            answer = m

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
INF = int(1e9)



ans = INF
def main():
    N, M, X = map(int, readline().split())

    

    
    
    costs = []
    score = []
    for _ in range(N):
        c, *d = map(int, readline().split())
        costs.append(c)
        score.append([i for i in d])

    
    
    
    bit = []
    
    def dfs():
        global ans
        
        if len(bit) == N:
            
            cost = 0
            
            sumScore = [0 for _ in range(M)]
            for i in range(N):
                if bit[i]:
                
                    cost += costs[i]
                    for j in range(M):
                        
                        sumScore[j] += score[i][j]

            
            
            flag = True 
            for i in range(M):
                if sumScore[i] < X: 
                    flag = False

            
            if flag:
                
                ans = min(ans, cost)
                return 
            return 

        
        
        for i in range(2): 
            
            bit.append(i)
            
            dfs()
            
            bit.pop()

    dfs()
    if ans == INF:
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
INF = int(1e9)



ans = INF
def main():
    N, M, X = map(int, readline().split())

    

    
    
    costs = []
    score = []
    for _ in range(N):
        c, *d = map(int, readline().split())
        costs.append(c)
        score.append([i for i in d])

    
    
    
    bit = []
    
    def dfs():
        global ans
        
        if len(bit) == N:
            
            cost = 0
            
            sumScore = [0 for _ in range(M)]
            for i in range(N):
                if bit[i]:
                
                    cost += costs[i]
                    for j in range(M):
                        
                        sumScore[j] += score[i][j]

            
            
            flag = True 
            for i in range(M):
                if sumScore[i] < X: 
                    flag = False

            
            if flag:
                
                ans = min(ans, cost)
                return 
            return 

        
        for i in range(2): 
            bit.append(i)
            dfs()
            
            bit.pop()

    dfs()
    if ans == INF:
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
N, M, X = map(int, input().split())
Books = []
Skills = [0] * M
cost = 0
res = 10 ** 9

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

for bit in range(2 ** N):
    for i in range(N):
        if (bit >> i) & 1:
            for j in range(M):
                Skills[j] += Books[i][j+1]
            cost += Books[i][0]
    if all(a >= X for a in Skills):
        res = min(res, cost)
    cost = 0
    Skills = [0] * M

print(res if res != (10 ** 9) else -1)

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

ans = float('inf')
for p in range(2 ** n):
    total = 0
    line = [0] * m
    for i in range(n):
        if (p >> i) & 1:
            for j in range(m):
                line[j] += a[i][j]
            total += c[i]
    if all((num >= x for num in line)):
        ans = min(ans, total)

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

Solution (Python):
import numpy as np
N,M,X = (int(x) for x in input().split())
Data  = np.zeros((N,M+1),dtype=int)
for Book in range(0,N):
    Data[Book,:] = np.array([int(x) for x in input().split()])

minCost = float('inf')
OK_Flag = 0
for Pt in range(0,pow(2,N)):
    strA  = (list(format(Pt,'0'+str(N)+'b')))
    intA  = np.array([int(x) for x in strA],dtype=bool)
    Price = np.sum(intA.reshape(N,1)*Data,axis=0)
    if (all(Price[1:]>=np.full(M,X))) & (Price[0]<minCost):
        minCost = Price[0]
        OK_Flag = 1

if OK_Flag:
    print(minCost)
else:
    print('-1')

Solution (Python):
N,M,X=map(int,input().split())
C=[]
A=[]
for _ in range(N):
    Y=list(map(int,input().split()))
    C.append(Y[0])
    A.append(Y[1:])
res=10**9
for bit in range(2**N):
    sums=0
    array=[0]*M
    for i in range(N):
        if bit>>i&1:
            for j in range(M):
                array[j]+=A[i][j]
            sums+=C[i]
    if all((a>=X for a in array)):
        res=min(res,sums)

print(res if res!=10**9 else -1)

Solution (Python):
N,M,X=map(int,input().split())
C=[]
A=[]
for _ in range(N):
    Y=list(map(int,input().split()))
    C.append(Y[0])
    A.append(Y[1:])
res=10**9
for bit in range(2**N):
    sums=0
    array=[0]*M
    for i in range(N):
        if bit>>i&1:
            for j in range(M):
                array[j]+=A[i][j]
            sums+=C[i]
    array.sort()
    if array[0]>=X:
        res=min(res,sums)

print(res if res!=10**9 else -1)

Solution (Python):
n,m,x = map(int,input().split())
c=[]
a=[]
INF = float("inf")
stock = INF
for _  in range(n):
    c_temp,*a_temp = list(map(int,input().split()))
    c.append(c_temp)
    a.append(a_temp)

for bit in range(1 << n):
    cost_total = 0
    smart_total = [0]*m

    for i in range(n):
        if (bit >> i) & 1:
            
            smart = []
            cost_total += c[i]
            smart = a[i]
            for j , sm in enumerate(smart):
                smart_total[j] += sm
        
            
    judege = True
    for i in range(m):
        if smart_total[i] < x:
            judege = False
    if judege:
        stock = min(cost_total,stock)
if stock == INF:
    print("-1")
else:
    print(stock)

Solution (Python):

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

price_list = []
skillup = []
for i in range(n):
    book = list(map(int,input().split()))
    price_list.append(book[0])
    skill = []
    for j in range(m):
        skill.append(book[j+1])
    skillup.append(skill)

min_price = 10**10
for i in range(2**n):
    price = 0
    skill = [0] * m
    index = 0

    bits = "0" * (n - (len(bin(i))-2)) + str(bin(i))[2:len(bin(i))] 

    for bit in bits:
        if bit == "1":
            price += price_list[index]
            for s in range(m):
                skill[s] += skillup[index][s]
        index+=1
    check = [0] * m
    for s in range(m):
        if skill[s] >= x:
            check[s] = 1
    passed = 1
    for s in range(m):
        if check[s] == 0:
            passed = 0
    if passed:
        if price < min_price:
            min_price = price

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

Solution (Python):


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

ans = 99999999
for i in range(2 ** N):
    bag = []
    for j in range(N):
        if ((i >> j) & 1):
            bag.append(book_list[j])
    total_cost = 0
    skill = [0] * M
    enough = [0] * M
    for subject in bag:
        total_cost += subject[0]
        for k in range(M):
            skill[k] += subject[k+1]
            if skill[k] >= X:
                enough[k] = 1
    if 0 not in enough:
        if ans > total_cost:
            ans = total_cost

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

Solution (Python):
import numpy as np

def dfs(n,a,s):
  if n==0:
    return -1 if (a >= X).all()==False else s
  
  x=dfs(n-1,a+A[n-1],s+C[n-1])
  y=dfs(n-1,a,s)
  return y if x==-1 else x if y==-1 else min(x,y)

N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
  c,*tmp=map(int,input().split())
  A.append(np.array(tmp))
  C.append(c)

print(dfs(N,np.array([0]*M),0))

Solution (Python):


"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time,itertools
start_time = time.time()



def solve():
    ONLINE_JUDGE_SOLUTION = Codeforces.CodeforcesSolutions("1361","A","GET","POST")
    print(ONLINE_JUDGE_SOLUTION)
                


 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
    sys.stdout.close()
    

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 

def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

class Codeforces():
    def CodeforcesSolutions(id,question,get,post):
        n,m,x = invr()
        a = []
        c = []
        qwqw = []
        for i in range(n):
            s = inlt()
            c.append(s.pop(0))
            a.append(s)
        q = [i for i in range(n)]
        for i in range(n):
            w = list(itertools.combinations(q,i + 1))
            for j in range(len(w)):
                qw = w[j]
                qq = [0] * m
                ww = 0
                for k in range(len(qw)):
                    ww = ww + c[qw[k] - 1]
                    qq = [qq[l] + a[qw[k] - 1][l] for l in range(m)]
                if min(qq) >= x:
                    qwqw.append(ww)
        if qwqw:
            return(min(qwqw))
        return(-1)
                    


        q = min(a,d)
        w = min(b,d - q)
        qw = min(d - q - w,c)
        return(q - qw)
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Solution (Python):
n, m, x = map(int, input().split())
A = []
for i in range(n):
    A.append(list(map(int, input().split())))
ans = 10 ** 7
t = 2 ** n
for i in range(t):
    s = [0 for _ in range(m)]
    c = 0
    bin_i = format(i, '012b')
    if len(bin_i) > n:
        bin_i = bin_i[12-n:]
    for j in range(n):
        if bin_i[j] == "1":
            for k in range(m):
                s[k] += A[j][k+1]
            c += A[j][0]
    if  c < ans and min(s) >= x:
        ans = c
if ans == 10 ** 7:
    print(-1)
else:
    print(ans)

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
n,m,x=map(int,input().split())
A=[[int(i) for i in input().split()] for _ in range(n)]
ans=float("inf")
for i in range(2**n):
  B=[0]*(m+1)
  for j in range(n):
    if i&(1<<j):
      for k in range(m+1):
        B[k]+=A[j][k]
  if min(B[1:])>=x:
    ans=min(ans,B[0])
print(-1 if ans==float("inf") else ans)