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):
n,m,x = map(int,input().split())

box = []
for i in range(n):
  line = list(map(int,input().split()))
  box.append(line)
anss = []

for i in range(2**n):
  ans = [0 for i in range(m+1)]
  count = 0
  for j in range(n):
    if (i>>j)&1:
      for l in range(m+1):
        ans[l] += box[j][l]
  for k in range(1,m+1):
    if ans[k]>=x:
      count += 1
  if count == m:
    anss.append(ans[0])
if len(anss) == 0:
  print(-1)
else:
  print(min(anss))

Solution (Python):
import numpy as np

[n,m,x] = [int(x) for x in input().split()]
data = np.array([[int(x) for x in input().split()] for _ in range(n)])

ans = []

for i in range(2**(n)):
    temp = np.array([0]*(m+1))

    for j in range(n):
        if (i >> j) & 1:
            temp = temp + data[j]
    
    for k in temp[1:]:
        if k < x:
            break
    else:
        ans.append(temp[0])

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

Solution (Python):
import sys
import itertools
from typing import Callable, List, NoReturn, Tuple

import numpy as np


def main() -> NoReturn:
    scan: Callable[[], str] = sys.stdin.readline

    n, m, x = map(int, scan().rstrip().split())  
    book_matrix: np.ndarray = np.array(
        tuple(
            tuple(int(_1) for _1 in scan().rstrip().split()) for _2 in range(n)
        )
    )

    grasp_matrix = np.split(book_matrix, [1], axis=1)[1]
    max_grasp: np.ndarray = np.sum(grasp_matrix, axis=0)

    if not (max_grasp >= x).all():
        print(-1)
        return

    all_books = tuple(range(n))
    prices: List[int] = []

    for k in range(1, n + 1):
        for combs in itertools.combinations(all_books, k):
            total: np.ndarray = np.zeros(m + 1)
            for book in combs:
                total += book_matrix[book]
            if (total[1:] >= x).all():
                prices.append(total[0])

    print(int(min(prices)))


if __name__ == '__main__':
    main()

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

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

min_cost = 10**8

for i in range(2**n):
    a = [0] * m
    cost = 0
    for j in range(n):
        if (i >> j) & 1:
            cost += book[j][0]
            for k in range(m):
                a[k] += book[j][k+1]

    valid = True
    for j in range(m):
        if a[j] < x:
            valid = False
            break

    if valid:
        min_cost = min(min_cost, cost)

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

Solution (Python):
import numpy as np

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

C = [0] * N
A = [[0]] * N

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

candidates = []

def iter(i, cost, learned):
    if(all(elm >= X for elm in learned)):
            candidates.append(cost)

    i += 1

    if(i >= N): return 0

    iter(i, cost, learned)
    iter(i, (np.array(cost) + np.array(C[i]).tolist()), (np.array(learned) + np.array(A[i])).tolist())


iter(0, C[0], A[0])
iter(0, 0, [0]*M)

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

Solution (Python):
import numpy as np
from itertools import combinations
n, m , x = map(int, input().split())
skill_dic = {} 
for i in range(n):
    tmp = list(map(int, input().split()))
    skill_dic[i] = {'cost':tmp[0],'skills':tmp[1:]}

def calc_cost(skill_books, skill_dic,x):
    skill_nums = len(skill_dic[0]['skills'])
    skills = np.zeros(skill_nums)
    for i in skill_books:
        skills += skill_dic[i]['skills']
    skills = skills.reshape(-1, skill_nums)
    if np.all(skills >= x): return sum([ skill_dic[skill_book]['cost'] for skill_book in skill_books ])
    return None 

i = 1
cost_list = []
while i <= len(skill_dic.keys()):
    book_comb = combinations(skill_dic.keys(),i)
    for pattern in book_comb:
        cost = calc_cost(list(pattern),skill_dic, x)
        if cost is not None: cost_list.append(cost)
    i += 1
print(min(cost_list) if cost_list != [] else -1)

Solution (Python):
from itertools import product

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

minimum_cost = float('inf')

buy_selections = product([1, 0], repeat=n)
for selection in buy_selections:
    bought_books = [books[i] for i in range(n) if selection[i]]
    
    total_each = [0] * (m+1)
    for book in bought_books:
        for i in range(m+1):
            total_each[i] += book[i]
    
    if any([total < x for total in total_each[1:]]):
        continue
    if total_each[0] < minimum_cost:
        minimum_cost = total_each[0]

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

Solution (Python):
import itertools

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

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

flag_i = False
min_cost = 10**7

for i in range(1, N+1):
    comb_list = list(itertools.combinations(range(N), i))
    
    for comb in comb_list:
        know = [0] * M
        cost = 0
        for book in comb:

            for i in range(M):
                know[i] += A[book][i]
            cost += C[book]
        
        
        flag = True
        for i in range(M):
            if (know[i] < X):
                flag = False
              
        
        if (flag):
            flag_i = True
            
            if (min_cost > cost):
                min_cost = cost
if (flag_i):
    print(min_cost)
    exit(0)

print(-1)

Solution (Python):

import sys
from itertools import *

def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word
tokens = iterate_tokens()
n=int(next(tokens))
m=int(next(tokens))
x=int(next(tokens))
c=[0]*n
a=[[0]*m for _ in range(n)]
for i in range(n):
    c[i]=int(next(tokens))
    for j in range(m):
        a[i][j]=int(next(tokens))

b=[]
def sumb(b):
    ret=0
    for i in range(n):
        if b[i]==1:
            ret+=c[i]
    return ret

def chk_mok(b):
    gak=[0]*m
    for i in range(n):
        if b[i]==1:
            for j in range(m):
                gak[j]+=a[i][j]
    ret=True
    for j in range(m):
        if gak[j]<x:
            ret=False
    return ret

if not chk_mok([1]*n):
    print(-1)
    exit()

ans=sum(c)

def buy(b, i):
    global ans
    if i==n:
        if chk_mok(b):
            ans=min(ans, sumb(b))
    else:
        buy(b+[0], i+1)
        buy(b+[1], i+1)

buy([0], 1)
buy([1], 1)

print(ans)

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

def all(l):
    for v in l:
        if v<x:
            return False
    return True

D=[[] for _ in range(2**n)]
for x1 in range(2**n):
    w=x1
    for y in range(n):
        D[x1].append(w%2)
        w//=2

for i in range(2**n):
    r=[0]*m
    by=0
    for p in range(n):
        if D[i][p]:

            for j in range(m):
                r[j]+=z[p][1:][j]
            by+=z[p][0]

    if all(r):
        Nedan.append(by)
print(-1 if Nedan==[] else min(Nedan))

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

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

c = [ca[i][0] for i in range(n)]

a = [0]*m
costs = []

for i in range(2**n):
    cost = 0
    
    for j in range(n):
        if (i>>j) & 1:
            cost += c[j]
            for k in range(m):
                a[k] += ca[j][k+1]
    
    flag = True
    for l in range(m):
        if a[l] < x:
            flag = False
    if flag:
        costs.append(cost)
    a = [0]*m
if costs == []:
    print(-1)
else:
    print(min(costs))

Solution (Python):
N, M, X = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(N)]
ans = 10 ** 18
chk = [0] * N

def dfs(next):
    global ans
    if next == N:
        rikai = [0] * M
        total = 0
        ansF = True
        for i in range(N):
            if chk[i] == 1:
                total += ca[i][0]
                for j in range(M):
                    rikai[j] += ca[i][j + 1]

        for i in rikai:
            if i < X:
                ansF = False
                break
        if ansF:
            ans = min(ans, total)
        return

    for i in range(2):
        chk[next] = i
        dfs(next + 1)
    return

dfs(0)

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

Solution (Python):
from itertools import combinations


def main():
    N, M, X = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    money = float('inf')

    for i in range(N):
        
        a = combinations(range(N), i + 1)
        for s in a:
            tmp_money = 0
            rikai = [0] * M
            
            for x in s:
                
                tmp_money += A[x][0]
                for m in range(M):
                    rikai[m] += A[x][m + 1]
            
            if min(rikai) >= X:
                money = min(money, tmp_money)
    if money == float('inf'):
        print(-1)
    else:
        print(money)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
n,m,X = map(int,input().split())
list_input = []
for x in range(n):
  list_input.append(list(map(int,input().split())))
List = []
List_array = []
for x in list_input:
  List.append(x[0])
  List_array.append(x[1:])
a = np.array(List_array)
List_ans = []
for i in range(2**n):
  s = 0
  t = np.array([0]*m)
  for j in range(n):
    if (i>>j)&1 == 1:
      s += List[j]
      t += a[j]
  if min(t) >= X:
    List_ans.append(s)

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

Solution (Python):
import sys

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

a = []
for i in range(n):
  a.append(list(map(int,input().split())))
  
money_min = sys.maxsize
ans = False

for i in range(2 ** n):
  s = bin(i).replace('0b','')
  s = s.zfill(n)
  
  tmp = [0] * (m+1)
  money = 0

  for j in range(len(s)):
    if s[j] == '1':
      money += a[j][0]
      for k in range(1,m+1):
        tmp[k] += a[j][k]
        
  flag = True
  for j in range(1,m+1):
    if tmp[j] < x:
      flag = False
      break
      
  if flag:
    money_min = min(money_min,money)
    ans = True
  
if ans:
  print(money_min)
else:
  print(-1)

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

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

ans = 10 ** 7
for i in range(1 << N):
    s = [0] * M
    kari = 0
    for j in range(N):
        if (i >> j) % 2 == 1:
            kari += A[j][0]
            for k in range(M):
                s[k] += A[j][k+1]
    if min(s) >= X:
        ans = min(ans, kari)

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

Solution (Python):
import numpy as np

n, m, x = list(map(int, input().split()))
a = [list(map(int,input().split())) for l in range(n)]
x_list = [x]*m
s = range(2**n)
ans = 10**10
count = 0
for i in s:
    y = np.zeros(m+1)
    for j in range(n):
        if ((i>>j)&1):
            y = y+np.array(a[j])
    
    if np.all(np.array(y[1:])>=np.array(x_list)):
        count = 1
        ans = min(ans, y[0])  

if count == 1:
    print(int(ans))     
else:
    print(-1)

Solution (Python):
import copy
n,m,x=[int(_) for _ in input().split()]
Cmat=[[int(_) for _ in input().split()] for i in range(n)]
lista=[]
money=[]

visited=0
def dfs(lista,visited):
    global x
    global money
    skill=[0]*m
    total=0
    for i,j in enumerate(lista):
        for index,ja in enumerate(Cmat[j]):
            if index==0:
                total+=ja
            else:
                skill[index-1]+=ja
    if lista and all([i>=x for i in skill]):
        
        money.append(total)    
    elif visited<n:
        dfs(lista+[visited],visited+1)
        dfs(lista,visited+1)

dfs(lista,visited)
if money:
    print(min(money))
else:
    print(-1)

Solution (Python):
inputs = open(0).readlines()
n, m, x = map(int, inputs[0].split())
CA = [list(map(int, x.split())) for x in inputs[1:]]
ans = 10**9
for i in range(2 ** n):
    cost = 0
    B = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            c, *A = CA[j]
            cost += c
            for k in range(m):
                B[k] += A[k]
    if all(b >= x for b in B):
        ans = min(ans, cost)
if ans == 10**9:
    ans = -1
print(ans)

Solution (Python):
N,M,X = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
money = [A[i][0] for i in range(N)]
A = [A[i][1:] for i in range(N)]
test = [[A[i][j] for i in range(N)] for j in range(M)]
test = list(map(sum,test))
ans = 0
if min(test) < X:
    ans = -1

if ans == 0:
    from itertools import product
    for cond in product([True,False], repeat=N):
        tmparr = [0] * M
        cost = 0
        for i,j in enumerate(cond):
            if j:
                tmparr = [tmparr[k] + A[i][k] for k in range(M)]
                cost += money[i]
        if min(tmparr) >= X:
            if ans == 0:
                ans = cost
            else:
                ans = min(ans,cost)

print(ans)

Solution (Python):
n, m, x = map(int, input().split())
c = []*n
list = [input().split() for l in range(n)]
ans = float('inf')
op_cnt = n
for i in range(2 ** op_cnt):
  flag = 1
  progress =[0]*m
  cost = 0
  op = [0] * op_cnt  
  for j in range(op_cnt):
      if ((i >> j) & 1):
          op[op_cnt - 1 - j] = 1
          cost += int(list[op_cnt - 1 - j][0])
          for k in range(m):
            progress[k] += int(list[op_cnt-1-j][k+1])
   
  for l in range(m):
    if progress[l] < x:
      flag = 0
      break
  if flag == 1:
    ans = min(ans,cost)
if ans == float('inf'):
  print(-1)
else:
  print(int(ans))

Solution (Python):
import numpy as np
n, m, x = map(int, input().split())
texts = []

for i in range(n):
    array = list(map(int, input().split()))
    texts.append(array)
num = 2**n
min_money = 10**20
for i in range(num):
    flg = True
    t = str(format(i, 'b')).zfill(n)
    total = np.zeros(m+1)
    for j in range(n):
        if t[j] == '1':
            total += texts[j]
    y = total[1:]
    for k in y:
        if k < x:
            flg = False
            break
    money = total[0]
    if money < min_money and flg is True:
        min_money = money

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

Solution (Python):
import numpy as np
import itertools
[N,M,X]=map(int,input().split())
l=[]
for i in range(N):
    
    l.append(list(map(int,input().split())))
l=np.array(l)
num=np.array([i for i in range(N)])
C = l[:,0]
A = l[:,1:]
ans = -1
for i in range(N):
    for c in itertools.combinations(num,i+1):
        score = np.zeros(M)
        cost = 0
        for j in c:
            score=score+A[j]
            cost = cost+C[j]
        if np.min(score)>=X:
            if ans>=cost or ans ==-1:
                ans = cost
if ans ==0:
    ans = -1
print(ans)

Solution (Python):
import itertools

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

Money=0

lst=range(N)
combs = []

for i in range(1, len(lst)+1):
    els = [list(x) for x in itertools.combinations(lst, i)]
    combs.extend(els)

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


Tmp=[0]*(len(combs))

for i in range(len(combs)):
    Skill=[0]*M
    for j in range(len(combs[i])):
        for k in range(M):
            Skill[k]+=inList[combs[i][j]][k+1]
        Tmp[i]+=inList[combs[i][j]][0]

    ok=True
    for k in range(M):
        if(Skill[k]<X):
            ok=False
    if(ok==False):
        Tmp[i]=10000000000

if(min(Tmp)==10000000000):
    print(-1)
else:
    print(min(Tmp))

Solution (Python):
import itertools
n,m,x = map(int, input().split())
a = []
res = 10000000
for i in range(n):
  a.append(list(map(int, input().split())))
for i in range(1,n+1):
  l = itertools.combinations(range(n),i)
  for j in l:
    tmp = [0]*(m+1)
    for k in j:
      for o in range(m+1):
        tmp[o] += a[k][o]
    flg = 0
    for o in range(1,m+1):
      if tmp[o] < x:
        flg = 1
    if flg == 0:
      res = min(res, tmp[0])
if res == 10000000:
  print(-1)
else:
  print(res)

Solution (Python):
import numpy as np
from copy import copy

N, M, X = map(lambda x: int(x), input().split(" "))

Ms = [[0] * (M+1)]
Ms = np.array(Ms)
for _ in range(N):
    n = list(map(lambda x: int(x), input().split(" ")))
    temp_Ms = copy(Ms)
    for m in Ms:
        temp_Ms = np.append(temp_Ms, np.array([m+n]), axis=0)
    Ms = temp_Ms

Cs = Ms[:, 0]
Ms = np.delete(Ms, 0, 1)
result = float("inf")

for i in range(len(Ms)):
    if np.all(Ms[i] >= X):
        result = min(result, Cs[i])

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

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

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

minC = 10000000

for i in range(0,pow(2,N),1):
    C = 0
    A = [0 for i in range(0,M+1,1)]
    for j in range(N):
        if((i>>j)&1):
            for k in range(1,M+1,1):
                A[k]+= CA[j][k]
            C += CA[j][0]
    flag = False
    for k in range(1,M+1,1):
        if A[k] < X:
            flag = True
    if flag:
        continue

    if C < minC:
        minC = C

if minC != 10000000:
    print(minC)
else:
    print(-1)

Solution (Python):

import queue

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

cost = -1
score = -1
shan = -1

book_c = []
book_a = []
index = [i for i in range(M)]

def judge(c,a):
    m = min(a)
    jud = -1
    if m >= X:
        jud = c
    return jud
    
for i in range(N):
    b = input().split()
    book_c.append(int(b[0]))
    b = b[1:]
    box = []
    for j in b:
        box.append(int(j))
    book_a.append(box)

q = queue.Queue()
q.put('0')
q.put('1')
mak = q.get()
order = len(mak)

while order < N:
    mallo = '0' + mak
    mally = '1' + mak
    q.put(mallo)
    q.put(mally)
    mak = q.get()
    order = len(mak)

q.put(mak)

while not q.empty():
    score = 0
    mak = q.get()
    nas = [int(k) for k in mak]
    anad = [0] * M
    
    for c,kk in zip(book_c,nas):
        score += (c * kk)

    for asa,kk in zip(book_a,nas):
        for ind,kok in enumerate(asa):
            anad[ind] += (kok * kk)

    shan = judge(score,anad)
    if cost == -1:
        cost = shan
    elif shan != -1:
        cost = min(cost,shan)
            

print("{}".format(cost))

Solution (Python):
import numpy as np

def python_list_add(in1, in2):
    wrk = np.array(in1) + np.array(in2)
    return wrk.tolist()

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

for i in range(2 ** n):
    bag = []
    for j in range(n):  
        if ((i >> j) & 1):  
            bag.append(j)  
    
    p = 0
    org = [0]*m
    for k in bag:
        p += li[k][0]
        pos = li[k][1:]
        org = python_list_add(org, pos)
    if all(l >= x for l in org): 
        ans.append(p)


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

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

price = {}
for i in range(2 ** n):
    rikai = []
    total = 0
    for j in range(n):  
        if ((i >> j) & 1):  
            rikai.append(a[j][1:])  
            total += a[j][0]  
    price[total] = rikai







def python_list_add(in1, in2):
   return list(map(sum, zip(in1, in2)))

flag = False
minp = (10 ** 5) * 12
for k,v in price.items():
    r = [0]*m
    for i in range(len(v)):
        r = python_list_add(r, v[i])
    if min(r) >= x:
        minp = min(minp, k)
        flag = True

if flag:
    print(minp)
else:
    print("-1")

Solution (Python):


import itertools
import numpy as np

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

data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data = np.array(data)


ans = 10**6*12
for i in itertools.product([0, 1], repeat=n):
    
    data_tmp = np.zeros(m+1, dtype=np.int)
    for index in range(len(i)):
        if i[index] == 0:
            continue
        data_tmp += data[index, :]

    if np.all((data_tmp[1:] >= x)):
        ans = min(ans, data_tmp[0])
        

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

Solution (Python):
import sys
import math
import itertools
import collections

def solve(N,M,X,C,A):
    lis = [i for i in range(N)]
    ans = []
    for k,_ in enumerate(lis,1):
        for c in itertools.combinations(lis,r=k):
            tmp = 0
            dic = {key:0 for key in range(M)}
            for i in set(c):
                tmp += C[i]
                for n,a in enumerate(A[i]):
                    dic[n] += a
            for m in range(M):
                if(dic[m] < X):
                    break
            else:
                ans.append(tmp)
    return min(ans) if(ans != []) else -1
def main():
    N,M,X = map(int,input().split())
    C = []
    A = []
    for _ in range(N):
        tmp = list(map(int,input().split()))
        C.append(tmp.pop(0))
        A.append(tmp)
    
    print(solve(N,M,X,C,A))

if __name__ == "__main__":
    main()

Solution (Python):
import sys
import numpy as np
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

lst=[]
cnt=0
ans=100000000
for _ in range(n):
	a=list(map(int,readline().split()))
	lst.append(a)
	
for i in range(1,2 ** n):
    bag = []
    
    for j in range(n):
      if ((i >> j) & 1):  
      	bag.append(lst[j])  
    
    cab=np.array(bag)
    sum=np.sum(cab,axis=0)
    
    cnt=0
    for k in range(m):
    	
    	if sum[k+1]>=x:
    		cnt+=1
    	if cnt==m:
    		ans=min(ans,sum[0])
    		
if ans==100000000:
	print(-1)
else:
	print(ans)

Solution (Python):
def main():
    N,M,X  = map(int, input().split()) 
    C = []
    for _ in range(N):
        c=list(map(int, input().split()))
        C.append(c)
    
    min = -1

    for i in range(2 ** N):
        bag = []
        OK = False
        for j in range(N):  
            if ((i >> j) & 1):  
                bag.append(C[j])
        sumlist=[0]*(M+1)
        for j in range(len(bag)):
            for k in range(M+1):
                sumlist[k] += bag[j][k]
        for j in range(M):
            if(sumlist[j+1] < X):
                OK = False
                break
            else:
                OK = True
        if OK and (min==-1 or min > sumlist[0]):
            min = sumlist[0]

    print (min)


if __name__ == '__main__':
    main()

Solution (Python):
result = float("inf")


def search(subset, depth, costs, x):
    if depth == len(costs):
        local_res = 0
        knowledge = [0] * (len(costs[0]) - 1)
        for i, cost in enumerate(costs):
            if i in subset:
                local_res += cost[0]
                for i, c in enumerate(cost[1:]):
                    knowledge[i] += c
        if done(knowledge, x):
            global result
            result = min(result, local_res)
    else:
        search(subset, depth + 1, costs, x)
        subset.add(depth)
        search(subset, depth + 1, costs, x)
        subset.remove(depth)


def done(knowledge, x):
    for item in knowledge:
        if item < x:
            return False
    return True


def solve(costs, x):
    search(set(), 0, costs, x)

    if result == float("inf"):
        return -1

    return result


if __name__ == "__main__":
    n, m, x = map(int, input().split())
    costs = [[int(x) for x in input().split()] for y in range(n)]
    print(solve(costs, x))

Solution (Python):
import itertools
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
comb = []
for i in range(1, n+1):
    comb.append(list(itertools.combinations(c, i)))
ans = []
for i in range(len(comb)):
    for j in range(len(comb[i])):
        flag = True
        for l in range(1, m+1):
            sum = 0
            for k in range(len(comb[i][j])):
                sum += comb[i][j][k][l]
            if sum < x:
                flag = False
                break
        if flag:
            cos = 0
            for k in range(len(comb[i][j])):
                cos += comb[i][j][k][0]
            ans.append(cos)
if ans:
    print(min(ans))
else:
    print(-1)

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

num = pow(2, n)
min_cost = -1
for count in range(num):
    a_list = [0] * m
    cost = 0
    for i in range(n):
        bit = pow(2, i)
        if (count // bit) % 2 == 1:
            for j in range(m):
                a_list[j] = a_list[j] + list_ca[i][j + 1]
            cost += list_ca[i][0]
    if min(a_list) >= x:
        if min_cost == -1:
            min_cost = cost
        elif min_cost > cost:
            min_cost = cost

print(min_cost)

Solution (Python):
import itertools
def ans(n, m, x, list_all):
    for i in range(m):
        sum_m=0
        for j in range(n):
            sum_m+=list_all[j][i+1]
        if x>sum_m:
            return -1
    price=pow(10,7)
    for i in itertools.product([0,1], repeat=n):
        list=[0]*(m+1)
        boo=True
        for j in range(n):
            if i[j]==1:
                for k in range(m+1):
                    list[k]+=list_all[j][k]
        for j in range(m):
            if list[j+1]<x:
                boo=False
        if boo:
            if price>list[0]:
                price=list[0]
    return price


n, m, x =(int(x) for x in input().split())
list_all=[]
for i in range(n):
    li_i=list(map(int, input().split()))
    list_all.append(li_i)
print(ans(n, m, x, list_all))

Solution (Python):
B, A, R = map(int, input().split())

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

V = 100000000

for i in range(1, 2 ** B):
	bag = []
	choniki = [0]*A
	for j in range(B):
		check = 0  
		if ((i >> j) & 1):  
			bag.append(P[j][0])
			for k in range (0, A):
				choniki[k]+=P[j][k+1]
			for l in range (0, A):
				if choniki[l] < R:
					check = 1
			if check == 0 and sum(bag) < V:
				V = sum(bag)

if V < 100000000:
	print(V)
else:
	print(-1)

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

lst = []
for i in range(2**N):
    lst.append(str(bin(i)))
    lst[i] = lst[i][2:]
    lst[i] = lst[i].zfill(N)

lst_res = []

for j in lst:
    res = [0]*(M+1)
    for k in range(N):
        if j[k] == "0":
            pass
        else:
            res = [x+y for (x,y) in zip(res,S[k])]
    for l in range(1,M+1):
        if res[l] < X:
            break
    else:
        lst_res.append(res[0])

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

Solution (Python):
import itertools
import numpy as np
 
N, M, X = map(int, input().split())
c_list = []
for _ in range(N):
  c_list.append(list(map(int, input().split())))
  
cand = []
e_list = [i for i in range(N)]
for n in range(1, N+1):
  for e in itertools.combinations(e_list, n):
    sum_list = np.zeros(M)
    sum_maney = 0
    for i in set(e):
      sum_list += np.array(c_list[i][1:])
      sum_maney += c_list[i][0]
    flag = True
    for m in range(M):
      if not sum_list[m] >= X:
        flag = False
    if flag:
      cand.append(sum_maney)
if cand == []:
  print(-1)
else:
  print(min(cand))

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


ans = 10000000
rikai = [0] * M
num = [0, 1]
num_list = list(itertools.product(num, repeat=N))


for a in num_list:
    rikai = [0] * M
    kane = 0
    for i in range(N):
        if a[i] == 1:
            for j in range(1, M + 1):
                rikai[j - 1] = rikai[j - 1] + C[i][j]
            kane += C[i][0]
    if all(elem >= X for elem in rikai):
        ans = min(ans, kane)
if ans == 10000000:
    print(-1)
else:
    print(ans)

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue

Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  
    n, m, x = map(int, input().split())
    ca = [list(map(int, input().split())) for i in range(n)]
    ans = float("inf")
    subsc = []  
    for i in range(1 << n):
        for j in range(n):
            if (i >> j)&1:
                subsc.append(ca[j])
        flag = True
        cost = 0 
        unst = 0 
        if len(subsc) == 0:
            continue  
        for j in range(1,m+1):
            for k in range(len(subsc)):
                unst += subsc[k][j]
            if unst < x:
                flag = False 
            unst = 0
        for j in range(len(subsc)):
            cost += subsc[j][0]
        if flag:
            ans = min(ans, cost)
        flag = True
        cost = 0
        subsc = []
    if ans == float("inf"):
        ans = -1
    print(ans)

if __name__ == "__main__":
    main()