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):
inputLine=input()
N=int(inputLine.split(" ")[0])
M=int(inputLine.split(" ")[1])
X=int(inputLine.split(" ")[2])

CandA=[]
for i in range(N):
    inputLine=input()
    CandA.append(inputLine.split(" "))

for i in range(len(CandA)):
    for j in range(len(CandA[i])):
        CandA[i][j] = int(CandA[i][j])

algorithmLevel = []
for i in range(M):
    algorithmLevel.append(0)

result = -1

for a1 in range(2):    
    for a2 in range(2):
        for a3 in range(2):
            for a4 in range(2):
                for a5 in range(2):
                    for a6 in range(2):
                        for a7 in range(2):
                            for a8 in range(2):
                                for a9 in range(2):
                                    for a10 in range(2):
                                        for a11 in range(2):
                                            for a12 in range(2):
                                                
                                                for i in range(M):
                                                    algorithmLevel[i] = 0

                                                for i in range(1, N+1):
                                                    for j in range(1, M+1):
                                                        if i == 1:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a1

                                                        if i == 2:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a2

                                                        if i == 3:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a3

                                                        if i == 4:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a4

                                                        if i == 5:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a5

                                                        if i == 6:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a6

                                                        if i == 7:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a7

                                                        if i == 8:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a8

                                                        if i == 9:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a9

                                                        if i == 10:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a10

                                                        if i == 11:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a11

                                                        if i == 12:
                                                            algorithmLevel[j-1] += CandA[i-1][j] * a12
                                                
                                                levelCheck = True
                                                for i in range(len(algorithmLevel)):
                                                    if algorithmLevel[i] < X:
                                                        levelCheck = False
                                                if levelCheck == True:
                                                    sumBooksPrice = 0
                                                    for i in range(1, N+1):
                                                        if i == 1:
                                                            sumBooksPrice += CandA[i-1][0] * a1

                                                        if i == 2:
                                                            sumBooksPrice += CandA[i-1][0] * a2

                                                        if i == 3:
                                                           sumBooksPrice += CandA[i-1][0] * a3

                                                        if i == 4:
                                                           sumBooksPrice += CandA[i-1][0] * a4

                                                        if i == 5:
                                                           sumBooksPrice += CandA[i-1][0] * a5

                                                        if i == 6:
                                                           sumBooksPrice += CandA[i-1][0] * a6

                                                        if i == 7:
                                                           sumBooksPrice += CandA[i-1][0] * a7

                                                        if i == 8:
                                                           sumBooksPrice += CandA[i-1][0] * a8

                                                        if i == 9:
                                                           sumBooksPrice += CandA[i-1][0] * a9

                                                        if i == 10:
                                                           sumBooksPrice += CandA[i-1][0] * a10

                                                        if i == 11:
                                                           sumBooksPrice += CandA[i-1][0] * a11

                                                        if i == 12:
                                                           sumBooksPrice += CandA[i-1][0] * a12

                                                    if result == -1:
                                                        result = sumBooksPrice                                                        
                                                    else:
                                                        if result > sumBooksPrice:
                                                            result = sumBooksPrice

print(result)

Solution (Python):
s = input().split()

N = int(s[0])
M = int(s[1])
X = int(s[2])

C = []
A = []

for i in range(N):
  t = input().split()
  C.append(int(t[0]))
  A_each = []
  for j in range(M):
    A_each.append(int(t[j+1]))
  A.append(A_each)
  
mini = -1
  
for i in range(2 ** N):
  bina = bin(i)[2:]
  money = 0
  result = []
  for x in range(M):
  	result.append(0)
  while(len(bina) < N):
    bina = "0" + bina
  for k in range(N):
    if bina[k] == "1":
      money += C[k]
      for j in range(M):
        result[j] += A[k][j]
  test = 0
  
  for n in range(M):
    if result[n] >= X:
    	test += 1
  if test == M:
    if money < mini or mini == -1:
      mini = money
      
print(mini)

Solution (Python):
import numpy as np
import itertools
n,m,x = map(int,input().split())
c = [0] * n
a = [0] * n
for i in range(n):
    p = list(map(int,input().split()))
    c[i] = p[0]
    a[i] = list(p[1:])
p_min = float('inf')

for i in range(n):
    for it in itertools.combinations(a,i+1):
        ans = [0] * m
        for li in it:
            ans += np.array(li)
        if all([item >= x for item in ans]):
            p_ans = 0
            for ind in it:
                p_ans += c[a.index(ind)]
            p_min = min(p_min,p_ans)
if p_min == float('inf'):
    print(-1)
else:
    print(p_min)

Solution (Python):
import itertools
n, m, x = map(int, input().split())
ca = []
for _ in range(n): ca.append(list(map(int, input().split())))
ans = 10 ** 19
t = False
for i in range(1, n+1):
    for idx in itertools.combinations(range(n), i):
        l = [0]*m
        c = 0
        for j in idx:
            for k, v in enumerate(ca[j][1:]):
                l[k] += v
            c += ca[j][0]
        if min(l) >= x:
            ans = min(ans, c)
            t = True
if t: print(ans)
else: print(-1)

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

stk = [[0 for _ in range(m + 1)]]
for i in range(n):
    cost = books[i][0]
    effect = books[i][1:]
    for j in range(len(stk)):
        sc = stk[j][0]
        tmp = []
        for k in range(m):
            tmp.append(effect[k] + stk[j][k + 1])
        stk.append([sc + cost] + tmp)

stk.sort()

for s in stk:
    cost = s[0]
    eff = s[1:]
    is_ok = True
    for e in eff:
        if e < x:
            is_ok = False
            break
    if is_ok:
        print(cost)
        exit()
print(-1)

Solution (Python):
import numpy as np

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

ans = 10**9
for i in range(2**n):
    cost = 0
    an = np.array([0]*m)
    for j in range(n):
        if (i >> j) & 1:
            cost += ca[j][0]
            an = an + np.array(ca[j][1:])
    
    if not np.any(an < x):
        ans = min(ans, cost)

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

Solution (Python):
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float('INF')
for i in range(2**N):
    bit = np.array([[i>>j&1 for j in range(N)]]).T
    temp = np.sum(CA*bit,axis=0).tolist()
    temp2 = []
    temp2.append(temp)
    for money,*x in temp2:
        for y in x:
            if y<X:
                break
        else:
            ans = min(ans,money)
print(ans if ans !=float('INF') else -1)

Solution (Python):
N,M,X = map(int,input().split())
c_list = [list(map(int,input().split())) for _ in range(N)]
cost_list = []
for i in range(2**N):
  achive = [0]*M
  achive_list = [0]*M
  cost = 0
  for j in range(N):
    if ((i>>j)&1)==1:
      cost = cost + c_list[j][0]
      for k in range(M):
        achive[k] = achive[k] + c_list[j][k+1]
        if achive[k] >= X:
          achive_list[k] = -1
  if sum(achive_list) == -1*M:
    cost_list.append(cost)
print(min(cost_list) if cost_list else -1)

Solution (Python):
cost = 10**9
N = 0
M = 0
X = 0

def solve(no, yn, book):
    global N, M, X, cost
    if no == N:
        understand = [0 for i in range(M)]
        c=0
        for i in range(len(yn)):
            if yn[i] == "Y":
                c += book[i][0]
                for j in range(M):
                    understand[j] += book[i][j+1]

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

        if possible:
            if cost > c:
                cost = c

    else:
        solve(no+1, yn+"Y", book)
        solve(no+1, yn+"N", book)

def main():
    global N, M, X, cost
    N, M, X = map(int, input().split())
    book = list()

    for i in range(N):
        b = [int(a) for a in input().split()]
        book.append(b)

    solve(0, "", book)
    if cost == 10**9:
        print(-1)
    else:
        print(cost)

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
N, M, X = [int(_) for _ in input().split()]
B = []
for i in range(N):
    B.append([int(_) for _ in input().split()])
l = [i for i in range(N)]
NUM = (10**5) * 12 + 1
ans = NUM
for i in range(1, N+1):
    C = itertools.combinations(l, i)
    for c in C:
        amount = 0
        U = [0 for i in range(M)]
        for k in range(i):
            amount += B[c[k]][0]
            for j in range(M):
                U[j] += B[c[k]][j+1]
        if min(U) >= X:
            ans = min(ans, amount)
if ans == NUM:
    print(-1)
else:
    print(ans)

Solution (Python):

import itertools


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



ans = []
for k in range(n+1):
    seq = list(itertools.combinations(list(range(n)), k)) 
    for l in seq:
        rikaido = [0 for _ in range(m)]
        cost = 0 
        for i in l:
            cost += c[i]
        for p in range(m):
            for q in l:
                rikaido[p] += a[q][p]
        
        ok = True
        for p in range(m):
            if rikaido[p] < x:
                ok = False
                break
        if ok: 
            ans.append(cost)

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

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

mini_money = (10**5)*12 + 1

for i in range(2 ** N):
    rikai = [0]*M
    money = 0
    for j in range(N):  
        if ((i >> j) & 1):  
            money += C_A[j][0]
            for k in range(M):
                rikai[k] += C_A[j][k+1]
                

    if min(rikai) >= X:
        mini_money = min(money,mini_money)
        

if mini_money == (10**5)*12+1:
    print("-1")
else:
    print(mini_money)

Solution (Python):
N, M, X = [int(x) for x in input().split()]


C = []
RIKAI = []
ans = 0

BOOK= []
for i in range(N):
    BOOK += [[int(x) for x in input().split()]]

ans = -1
MIN_PAY = 10**5 * 12 +1

for FLAG in range(2 ** N ):
    PAY = 0
    RIKAI = [0] * M
    for i in range(N):
        if FLAG >> i & 1:
            for j in range(M):
                RIKAI[j] = RIKAI[j] + BOOK[i][j+1]
            PAY += BOOK[i][0] 
    if min(RIKAI) >= X:
        MIN_PAY = min(PAY,MIN_PAY)
        

if MIN_PAY == 10 ** 5 * 12 +1:
    ans = -1
else:
    ans = MIN_PAY

print(ans)

Solution (Python):
from itertools import product
n, m, x = map(int, input().split())
c = []
a = []

for i in range(n):
    a.append(list(map(int, input().split())))
    c.append(a[-1].pop(0))

l = list(product([0, 1], repeat=n))
ans = [] * len(l)

for t in range(len(l)):
    s = [0] * m
    for i in range(n):
        for j in range(m):
            s[j] += l[t][i]*a[i][j]
    if min(s) >= x:
        ans_n = 0
        for i in range(n):
            ans_n += l[t][i]*c[i]
        ans.append(ans_n)

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

Solution (Python):
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
ans = float("inf")
for i in range(2**n):
    flag = True
    achive = [0]*m
    cost = 0
    for j in range(n):
        if i >> j & 1 == 1:
            cost += ca[j][0]
            for k in range(m):
                achive[k] += ca[j][k+1]

    for item in achive:
        if item < x:
            flag = False
    if flag:
        ans = min(ans, cost)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Solution (Python):
a = input().split(" ")
x = int(a[2])
m = int(a[1])
n = int(a[0])
s= []
p = [] 
for i in range(n):
  aa = input().split(" ")
  ss = []
  for ii in aa:
    ss.append(int(ii))
  s.append(ss[1:])
  p.append(ss[0])
    
from itertools import chain, combinations
def getPrice(indexes):
  t = 0
  for i in indexes:
    t += p[i]
  return t
def doesSatisfy(indexes):
  t = 0
  alg_totals = [0] * m
  for i in indexes:
    for ii in range(m):
      alg_totals[ii] += s[i][ii]
  for i in alg_totals:
    if i < x:
      return False
  return True

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

  
lowest = -1  
for i in list(powerset(list(range(n)))):
  price = getPrice(i)
  if doesSatisfy(i) and lowest == -1:
    lowest = price
  elif doesSatisfy(i) and price < lowest:
    lowest = price

print(lowest)

Solution (Python):
import numpy as np
import itertools
N, M, K = map(int, input().split())
Q = [np.asarray(input().split(), dtype=int) for i in range(N)]
min_cost = 10**9
def dfs(cost, C, depth=0):
  global min_cost
  if (C >= K).all():
    min_cost = min([cost, min_cost])
    return
  if depth == N:
    return
  dfs(cost+Q[depth][0], C + Q[depth][1:], depth+1)
  dfs(cost, C, depth+1)
  
dfs(0, np.zeros(M))
    
print(min_cost) if min_cost != 10**9 else print(-1)

Solution (Python):
import itertools

p = list(map(int,input().split()))
N = p[0]
M = p[1]
X = p[2]

l = [[int(i) for i in input().split()] for j in range(N)]
l_a = []
k_1 = list(range(1,N+1))
for i in itertools.combinations_with_replacement(k_1, N):
    l_a.append(list(set(i)))
l_a = list(map(list, set(map(tuple, l_a))))
l_v = float('inf')
f_1 = False
for ls in l_a:
    ls = list(set(ls))
    ans = [0] * M
    val = 0
    for a in ls:
        for ix,i in enumerate(l[a-1][1:]):
            ans[ix] += i
        val += l[a-1][0]
    b = [i for i in ans if i >= X]
    if len(b) == len(ans):
        l_v = min(l_v, val)
        f_1 = True
if f_1:
    print(l_v)
else:
    print(-1)

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

bookli = [[0 for I in range(M+1)] for II in range(N)]
for i in range(N):
    bookli[i] = list(map(int, input().split()))

ans=10**9

for j in range(1, 2**N):
    ansli = [0 for III in range(M+1)]
    keta = N
    for jj in range(keta):
        if ((j >> jj) & 1):
            ansli = [a + b for (a, b) in zip(ansli, bookli[jj])]

    for k in range(1, M+1):
        if ansli[k] >= X:
            pass
        else:
            break

        if k==M and ans > ansli[0]:
            ans=ansli[0]



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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M, X = MAP()

    C, A = [], []
    for i in range(N):
        c, *a = MAP()
        C.append(c)
        A.append(a)

    ans = INF
    for tup in list(product(range(2), repeat=N)):
        temp = [0 for _ in range(M)]

        for i in range(N):
            for j in range(M):
                if tup[i]:
                    temp[j] += A[i][j]

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

        if flag:
            money = 0
            for i in range(N):
                money += C[i] * tup[i]

            ans = min(money, ans)

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


if __name__ == '__main__':
    main()

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

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

costs=[]

for i in range(2**n):
    t=[0]*m
    cost=0
    for j in range(n):
        if ((i>>j)&1)==1:
            for k in range(m):
                t[k]+=book[j][k+1]
            cost+=book[j][0]
        
    if all(t[l]>=x for l in range(m)):
        costs.append(cost)

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

Solution (Python):


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

C_list = []
A_list = []

for i in range(N):
    inp = list(map(int, input().rstrip().split()))
    C_list.append(inp[0])
    A_list.append(inp[1:])


bit = 1 << N
max_price = sum(C_list)*2
min_price = max_price

for b in range(bit):
    price = 0
    study = [0]*M
    
    for i in range(N):
        if (b & (1 << i)):
            price += C_list[i]
            
            for j in range(len(A_list[i])):
                study[j] += A_list[i][j]
    
    if min(study) >= X:
        min_price = min(min_price, price)


print(min_price if min_price != max_price else -1)

Solution (Python):
import itertools
import numpy as np

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


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

min_ans = 10**7

l = range(N)

for i in range(N):
    c = list(itertools.combinations(l, i+1))
    for j in range(len(c)):
        
        target_book = np.array([CA[a] for a in c[j]])
        rikai = np.sum(target_book,axis=0)
        
        
        

        if min(rikai[1:]) >= X and min_ans > rikai[0]:
            
            
            
            min_ans = rikai[0]

if min_ans != 10**7:
    print(min_ans)
else:
    print(-1)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007



def ii(v, n):
	v += 2 ** 15
	ret = bin(v)[-n:]
	
	return ret

def vs(a,b):
	return [va+vb for va,vb in zip(a, b)]

def main():
	
	n, m, x = IN()
	
	bb = []
	for _ in range(n):
		dd = LIN()
		bb.append(dd)
	
	min_c = mod
	for i in range(2 ** n):
		c = 0
		mm = [0]*m
		rr = ii(i, n)
		for ik, keta in enumerate(rr):
			if keta == '1':
				l= bb[ik]
				c += l[0]
				mm = vs(mm, l[1:])
		if min(mm) >= x and c < min_c:
			min_c = c
	if min_c < mod:
		return min_c
	else:
		return -1
				
			
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

possible=[]


for k in range(2**N):
    bit = str(bin(k))
    count = 0
    howmuch = 0

    for l in range(1, M+1):
        for j in range(1, len(bit)-1):
            if bit[-j] == "1":
                count += A[j-1][l]
    
        if count < X:
            break
        count = 0
        

    else:
        for j in range(1, len(bit)-1):
            if bit[-j] == "1":
                howmuch += A[j-1][0]
        possible.append(howmuch)
if len(possible)>0:
    print(min(possible))
else:
    print(-1)

Solution (Python):
from operator import add

n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
cost = []
for i in range(2 ** n):
  total = 0
  algo = [0] * m
  for j in range(n):
    if ((i >> j) & 1):
      algo = map(add, algo, books[j][1::])
      total += books[j][0]

  count = 0
  for k in algo:
    if k >= x:
      count += 1
  
  if count == m:
    cost.append(total)

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

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

for i in range(1,2**(N+1)):
  bought = list(format(i, '0{}b'.format(N)))
  params = [0] * (M+1)
  for b, book in zip(bought, books):
    if b == '1':
      params = [pi+ai for pi,ai in zip(params,book)]
  for p in params[1:]:
    if p < X:
      break
  else:
    buy.append(params)

buy.sort()
print(buy[0][0] if len(buy) > 0 else -1)

Solution (Python):
import itertools
import numpy as np

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

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

ans = []
for k in range(1,N+1):
  rows = list(itertools.combinations(list(range(N)),k))
  for row in rows:
    Crow = 0
    Arow = np.array([0]*M)
    for j in range(len(row)):
      Crow += C[row[j]]
      Arow += np.array(A[row[j]])
    if all(a >=X for a in Arow):
      ans.append(Crow)
if len(ans) == 0:
  print(-1)
else:
  print(min(ans))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import numpy as np
    n,m,x=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    kanel=[]
    for i in range(2 ** n):
        kaul = np.array([0] * (m+1))
        for j in range(n): 
            if ((i >> j) & 1):  
                l[j]=np.array(l[j])
                kaul=kaul+l[j]
        flag=True
        for k in kaul[1:]:
            if k<x:
                flag = False
                break

        if flag:
            kanel.append(kaul[0])
    if kanel==[]:
        print(-1)
    else:
        print(min(kanel))
resolve()

Solution (Python):
from itertools import combinations

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

caa_list = []

for i in range(n):
  c, *aa = map(int, input().strip().split())
  caa_list.append((c, aa))

caa_list.sort(key=lambda x: x[0])

mc = 10 ** 9

for i in range(1, n+1):
  for caas in combinations(caa_list, i):
    sc = 0
    saa = [0] * m
    for c, aa in caas:
      sc += c
      for j in range(m):
        saa[j] += aa[j]
    if all(a >= x for a in saa):
      if mc > sc:
        mc = sc
        
if mc == 10 ** 9:
  print(-1)
else:
  print(mc)

Solution (Python):
n, m, x = list(map(int, input().split()))
_mt = [list(map(int, input().split())) for _ in range(n)]
cs = [r[0] for r in _mt]
anm = [r[1:] for r in _mt]

sumlst = lambda l1, l2: [i1+i2 for i1, i2 in zip(l1, l2)]

mat = [{} for _ in range(n + 1)]
mat[0][0] = (0, [0]*m)
for i in range(n):
    for j in mat[i]:
        w, seq = mat[i][j]
        
        mat[i + 1][w] = (w, seq)
        
        mat[i + 1][w + cs[i]] = (w + cs[i], sumlst(seq, anm[i]))

for k in sorted(mat[-1]):
    w, lst = mat[-1][k]
    if all(v >= x for v in lst):
        print(w)
        break
else:
    print(-1)

Solution (Python):
import numpy as np
import math
INF = float('inf')

def rec(k,und,ans):
	
	if(k==N):
		if(sum(und >= X) == len(und)):
			return ans
		else:
			return INF
	else:
		return min(rec(k+1,und+CA[k][1:],ans+CA[k][0]),rec(k+1,und,ans))	


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

CA = [[None for i in range(M+1)] for j in range(N)] 
for i in range(N):
	CA[i] = list(map(int,input().split()))


und =  np.array([0 for i in range(M)])	
ans = rec(0,und,0)
print(-1 if ans==INF else ans)

Solution (Python):






def     process(tab, tour, current, result,skill, N, M, X):
    finish = True
    for i in skill:
        if (i < X):
            finish = False
            break
    if (finish):
        if (result == -1):
            return current
        else:
            return min(result, current)
    if (tour == N or (current > result and result > -1)):
        return result

    current += tab[tour][0]
    for i in range(1, M+1):
        skill[i-1] += tab[tour][i]
    avec = process(tab, tour + 1, current, result, skill, N, M, X)
    
    if (result == -1 or (avec < result and avec > -1)):
        result = avec
    current -= tab[tour][0]
    for i in range(1, M+1):
        skill[i-1] -= tab[tour][i]
    sans = process(tab, tour + 1, current, result, skill, N, M, X)
    
    if (result == -1 or (sans < result and sans > -1)):
        result = sans
    return result


data = input().split()
n,m,x = int(data[0]), int(data[1]), int(data[2])


tab = []
for i in range (n):
    data = input().split()
    t = []
    for j in range (m+1):
        t.append(int(data[j]))
    tab.append(t)


skill = [0] * m
result = process(tab, 0, 0, -1, skill, n,m,x)
print(result)

Solution (Python):
import numpy as np
N, M, X = list(map(int, input().split()))
datas = []
for i in range(N):
    datas.append(np.array(list(map(int, input().split()))))

minv = np.inf
zeros = np.zeros(M+1)

for i in range(2**N):
    tmp = zeros.copy()
    for j in range(N):
        if (i >> j) & 1:
            tmp += datas[j]
            if np.all(tmp[1:len(tmp)] >= X):
                c = np.sum(tmp.T[0])
                if c < minv:
                    minv = c
                break
ret = int(minv) if minv != np.inf else -1
print(ret)

Solution (Python):
import itertools
N, M, X = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
li = []
for i in range(N+1):
    for j in itertools.combinations(range(N), i):
        sm = [0] * (M+1)
        for k in j:
            for l in range(M+1):
                sm[l] += a[k][l]
        if all(y >= X for y in sm[1:M+1]):
            li.append(sm[0])
if li == []:
    print(-1)
else:
    print(min(li))

Solution (Python):
N,M,K=map(int,input().split())
a=[]
ans=-1
for _ in range(N):
    A=list(map(int,input().split()))
    a.append(A)
for i in range(2**N):
    skill=[0]*(M)
    flag=0
    money=0
    for j in range(N):
        if ((i>>j)&1):
            money+=a[j][0]
            for k in range(1,M+1):
                skill[k-1]+=a[j][k]
    for l in skill:
        if l<K:
            flag=1
            break
    if flag==0:
        if ans==-1:
            ans=money
        else:
            ans=min(money,ans)
print(ans)

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

C_list = [list(map(int, input().split())) for i in range(N)]
import itertools

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

answer = 10 ** 9
for target in targets:
    result = [0] * (M + 1)
    for i, t in enumerate(target):
        if t == 1:
            for j in range(M + 1):
                result[j] += C_list[i][j]
        
    if min(result[1:]) >= X:
        
        answer = min(answer,result[0])
if answer == 10 ** 9:
    print(-1)
else:
    print(answer)