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 unittest
from io import StringIO
import sys


def resolve():
    n, m, x = [int(i) for i in input().split()]
    cc = []
    aa = []
    for comb in range(n):
        c, *a = [int(comb) for comb in input().split()]
        cc.append(c)
        aa.append(a)

    ans = float('inf')
    for comb in range(2**n):
        sum = 0
        xx = [0] * m
        for i in range(n):
            if (comb >> i) & 1:
                sum += cc[i]
                for j in range(m):
                    xx[j] += aa[i][j]
        for tx in xx:
            if tx < x:
                break
        else:
            ans = min(ans, sum)

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


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3 10
60 2 2 4
70 8 7 9
50 2 3 9"""
        output = """120"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 3 10
100 3 1 4
100 1 5 9
100 2 6 5"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """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"""
        output = """1067"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
import numpy as np
import itertools
n, m, x = [int(k) for k in input().split()]
c = np.zeros(n, dtype=int)
a = np.zeros((n, m), dtype=int)
for i in range(n):
    c[i], *a[i] = [int(k) for k in input().split()]
cost = np.sum(c) + 1
for nn in range(1,n+1):
    for k in itertools.combinations(np.argsort(c),nn):
        k = list(k)
        cs = np.sum(c[k].flatten())
        if cs > cost:
            continue
        rikai = np.sum(a[k],axis=0)
        if np.all(rikai >= x):
            cost = min(cost,cs)
if cost < np.sum(c) + 1:
    print(cost)
else:
    print(-1)

Solution (Python):

import numpy as np

n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
c = [a[i].pop(0) for i in range(n)]
ans = []
for s in range(1<<n):
    cost = 0
    mi = np.array([0]*m)
    for i in range(n):
        if (s>>i)&1:
            cost += c[i]
            mi += np.array(a[i])

    if np.all(mi >= x):
        ans.append(cost)
if ans:
    print(min(ans))
else:
    print('-1')

Solution (Python):
import copy

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

C = []
A = []

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


def IsOver(a):
    return all([i >= X for i in a])


INT_MAX = 1000000000
res_min = INT_MAX


def dfs(b_list, index):
    if index is N:
        cost = 0
        a = [0] * M
        for i in range(N):
            if b_list[i]:
                cost += C[i]
                for j in range(M):
                    a[j] += A[i][j]
        if IsOver(a):
            global res_min
            res_min = min(res_min, cost)
        return

    for use in [True, False]:
        _tmp = copy.copy(b_list)
        _tmp.append(use)

        dfs(_tmp, index+1)


dfs([], 0)

print(str(res_min) if res_min is not INT_MAX else str(-1))

Solution (Python):
N,M,X=map(int,input().split())
s=[list(map(int,input().split())) for i in range(N)]
t=[]
for i in range(1<<N):
  u=[0]*(M+1)
  for j in range(N):
    if ((i>>j)&1)==1:
      u=[u[k]+s[j][k] for k in range(M+1)] 
  for k in range(M):
    if u[k+1]<X:
      break
  else:
    t.append(u[0])
t.sort()
print(-1 if t==[] else t[0])

Solution (Python):
N,M,X=map(int,input().split())
s=[list(map(int,input().split())) for i in range(N)]
t=[-1]
for i in range(1<<N):
  u=[0]*(M+1)
  for j in range(N):
    if ((i>>j)&1)==1:
      u=[u[k]+s[j][k] for k in range(M+1)] 
  for k in range(M):
    if u[k+1]<X:
      break
  else:
    if t==[-1]:
      t.clear()
    t.append(u[0])
t.sort()
print(t[0])

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

A =  []
S = [0 for _ in range(N)] 
min_value = 0 
score=[0 for _ in range(M)] 

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

for x in range(N):
  min_value += A[x][0]


sucess = 0

for bit in range(2**N):
  for i in range(N):
    if (bit >> i) & 1:
      S.append(A[i][0])
      for x in range(M):
        score[x] += A[i][x+1]
  flag = 0
  
  for k in score:
    if k >= X:
      flag += 1
    if flag ==len(score):
      
      if min_value >= sum(S):
        min_value = sum(S)
        sucess += 1 
        
  score=[0 for _ in range(M)]
  S =[]
  
if sucess > 0:
	print(min_value)
else:
  print("-1")

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

A = [[] for _ in range(n)]
c = [0] * n

for i in range(n):
  c_as = list(map(int, input().split()))
  c[i], A[i] = c_as[0], c_as[1:]

INF = 10**9
ans = INF
  
for s in range(0, 1 << n):
  skill = [0] * m
  money = 0
  for i in range(n):
    if(s >> i) % 2 == 0:continue
    money += c[i]
    for j in range(m):
      skill[j] += A[i][j]
  ok = True
  for j in range(m):
    if skill[j] < x:
      ok = False
  if ok:
    ans = min(ans, money)
    
if ans == INF:
  ans = -1
  
print(ans)

Solution (Python):


import numpy as np
def func(ans, b_list, a_list, c_list, k, x):
    if k == 0:
        b_list = np.asarray(b_list)
        x_list = np.dot(b_list, a_list)
        if np.all(x_list >= x):
            return np.inner(c_list, b_list)
        else:
            return ans
    ans = min(ans, func(ans, b_list + [1], a_list, c_list, k - 1, x))
    ans = min(ans, func(ans, b_list + [0], a_list, c_list, k - 1, x))
    return ans

n, m, x = map(int, input().split())
c_list = [] 
a_list = []
for i in range(0, n):
    c, *a = map(int, input().split())
    c_list.append(c)
    a_list.append(a)
ans = float("inf")
c_list = np.asarray(c_list)
a_list = np.asarray(a_list)
ans = min(ans, func(ans, [1], a_list, c_list, n - 1, x))
ans = min(ans, func(ans, [0], a_list, c_list, n - 1, x))

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

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

inf = int(1e20)
n, m, x = map(int, input().split())
_ = [[int(x) for x in input().split()] for _ in range(n)]
CA = np.array(_, dtype=int)
ans = inf
for indices in product([False, True], repeat=n):
    sums = np.sum(CA[np.array(indices)], axis=0)
    if min(sums[1:]) >= x:
        ans = min(ans, sums[0])
print(ans if ans != inf else '-1')

Solution (Python):
n,m,x=map(int,input().split())
C=list()
A=list()
for i in range(n):
    X=list(map(int,input().split()))
    C.append(X[0])
    A.append(X[1:])
import itertools as it
V=list(it.product([0,1],repeat=n))
S=[10**7]*len(V)
for i in range(len(V)):
    Z=V[i]
    L=[0]*m
    for j in range(m):
        for k in range(n):
            L[j]+=A[k][j]*Z[k]
    if min(L)>=x:
        s=0
        for k in range(n):
           s+=C[k]*Z[k]
        S[i]=s
if  min(S)==10**7:
    print(-1)
else:
    print(min(S))

Solution (Python):
nmx = input('')
n = int(nmx.split(' ')[0])
m = int(nmx.split(' ')[1])
x = int(nmx.split(' ')[2])

clist=[]
alist=[]
for i in range(n):
    ca = input('')
    c = ca.split(' ')[0]
    clist.append(c)
    a = []
    for j in range(1,m+1):
        a.append(ca.split(' ')[j])
    alist.append(a)

min_price=99999999999
for i in range(2**n):
    skilllist=[0]*m
    buylist = [0]*n
    cost=0
    for j in range(n):
        if (i>>j )&1:
            buylist[j]=1
            cost+=int(clist[j])
            a = alist[j]
            for k in range(m):
                skilllist[k]+=int(a[k])

    ok = True
    for skill in skilllist:
        if skill < x:
            ok = False
    if ok and cost < min_price:
        min_price=cost

if min_price == 99999999999:
    min_price=-1
print(min_price)

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

Solution (Python):
N,M,X = map(int,input().split())
CA= [list(map(int,input().split())) for i in range(N)]
ans = float('inf')
for i in range(2**N):
    ci = 0
    lista = [0 for i in range(M)]
    for j in range(N):
        if (i >> j)&1 == 1:
            ci += CA[j][0]
            for k in range(M):
                lista[k] += CA[j][k+1]
    if min(lista) >= X:
        ans = min(ans,ci)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):

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


al=[]
cl=[]
for i in range(n):
    l=list(map(int,input().split()))
    cl.append(l[0])
    al.append(l[1:])

price_list=[]

for i in range(2**n):
    b=bin(i)
    score=[0 for k in range(m)]
    price=0

    for j in range(n):
        if ((i >> j) & 1):
            a=al[j]
            price+=cl[j]
            for k in range(m):
                score[k]+=a[k]
    if min(score)>=x:
        price_list.append(price)

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

Solution (Python):
n, m, x = map(int, input().split())
c, all = [],[]
for _ in range(n):
  tmp = list(map(int, input().split()))
  c.append(tmp[0])
  all.append(tmp[1:])
ans = float('inf')
for bit in range(1, 1<<n):
  cost = 0
  totalA = [0]*m
  for i, al in enumerate(all):
    if (1<<i) & bit:
      for j, a in enumerate(al):
        totalA[j] += a
      cost += c[i]
  check = True
  for a in totalA:
    if a < x: check = False
  if check: ans = min(ans, cost)
if ans == float('inf'): print(-1)
else: print(ans)

Solution (Python):
import numpy as np
import math
s = list(map(int, input().split()))
n = s[0]
m = s[1]
x = s[2]
book = []

for i in range(n):
    s = list(map(int, input().split()))
    book.append(s)
book=np.array(book)
ans=math.inf

for i in range(1<<n):

    skill = [0]*(m+1)
    for j in range(n):
        if i>>j & 1:
            for k,l in enumerate(book[j]):
                skill[k]+=l

    ok=True
    for j in range(1,m+1):
        if skill[j]<x :
            ok=False
            break
    if ok:
        ans=min(ans,skill[0])
if ans==math.inf:
    ans=-1
print(ans)

Solution (Python):
n, m, x = map(int, input().split())
sup = [0]*n 
cost = [0]*n

for i in range(n):
  CA = list(map(int, input().split()))
  cost[i] = CA[0]
  sup[i] = CA[1:]
  
ans = -1

for i in range(2**n):
  skills = [0]*m
  c = 0
  for j in range(n):
    if i>>j&1:
      c += cost[j]
      for k in range(m):
        skills[k] += sup[j][k]
  if min(skills)>=x:
    if ans < 0:
      ans = c
    elif c<ans:
      ans = c
    
print(ans)

Solution (Python):
n, m, x = map(int, input().split())
A = [[] for _ in range(n)]
cost = [0] * n
for i in range(n):
  c_as = list(map(int, input().split()))
  cost[i], A[i] = c_as[0], c_as[1:]
INF = 10**9
ans = INF
for s in range(0, 1 << n):
  smart = [0] * m
  cost_sum = 0
  for i in range(n):
    if (s >> i) % 2 == 0:
      continue
    cost_sum += cost[i]
    for j in range(m):
      smart[j] += A[i][j]
  ok = True
  for j in range(m):
    if smart[j] < x:
      ok = False
  if ok:
    ans = min(ans, cost_sum)
if ans == INF:
  ans = -1
print(ans)

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

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


INF = 10**9
ans = INF

for i in product([0,1], repeat=n):
    skill = [0] * m
    cost = 0
    for j in range(n):
        if i[j] == 1:
            for k in range(m):
                skill[k] += a[j][k]
            cost += c[j]
    if min(skill) >= x:
        ans = min(ans, cost)

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

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

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

maxi = 10 ** 5 * 12 + 1
ans = maxi

for bits in range(1, 2 ** n):
    scores = [0 for _ in range(m)]
    cost = 0
    for i in range(n):
        if bits >> i & 1:
            cost += arr[i][0]
            for j in range(m):
                scores[j] += arr[i][j + 1]

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

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

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

n, m, x = map(int, input().split())
c, a = [0] * n, [None] * n
for i in range(n):
    c[i], *a[i] = map(int, input().split())
ans = INF

for bit in range(2 ** n):
    s = [0] * m
    cost = 0
    for i in range(n):
        if bit >> i & 1:
            cost += c[i]
            for j in range(m):    
                s[j] += a[i][j]
    if min(s) >= x:
        ans = min(cost, ans)

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

Solution (Python):
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = float('Inf')
for i in range(2 ** n):
    sum_ = [0] * m
    cost = 0
    for j in range(n):
        
        if ((i >> j) & 1):
            cost += a[j][0]
            for k in range(m):
                sum_[k] += a[j][k + 1]
                
    flag = True
    for j in range(m):
        if sum_[j] < x:
            flag = False
    if flag:
        ans = min(ans, cost)
if ans == float('Inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
(n,m,x),*t=[[*map(int,t.split())]for t in open(0)]
m=M=9**9
for i in range(1,2**n):c,*a=map(sum,zip(*[t[j]for j in range(n)if i>>j&1]));m=min(m,M*(min(a)<x)or-~c)
print(m%M-1)

Solution (Python):
from itertools import combinations
import numpy as np
n,m,x = map(int,input().split())
a_list = []
price_list = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    price_list.append(tmp.pop(0))
    a_list.append(tmp)
    
all_list = [x for x in range(len(a_list))]
prices = []
for i in range(1,len(a_list)+1):
    for y in combinations(all_list,i):
        tmp = np.zeros(m)
        price = 0
        for ch in y:
            tmp += np.array(a_list[ch])
            price += price_list[ch]
        if np.all(tmp>=x):
            prices.append(price)
if prices != []:
    print(min(prices))
else:
    print(-1)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = 10 ** 9 + 100
ans = INF
def dfs(i, S, cost, C_list, A_list, N, M, X):
    global ans
    if i == N:
        ok = True
        for j in range(M):
            if S[j] < X:
                ok = False
                break
        if ok:ans = min(ans, cost)
        return
    dfs(i+1, S, cost, C_list, A_list, N, M, X)
    for j in range(M):
        S[j] += A_list[i][j]
    cost += C_list[i]
    dfs(i+1, S, cost, C_list, A_list, N, M, X)
    for j in range(M):
        S[j] -= A_list[i][j]
    cost -= C_list[i]
def main():
    global INF, ans
    N, M, X = map(int, input().split())
    C_list = []
    A_list = []
    for _ in range(N):
        C_A = list(map(int, input().split()))
        C_list.append(C_A[0])
        A_list.append(C_A[1:])
    S = [0 for _ in range(M)]
    cost = 0
    dfs(0, S, cost, C_list, A_list, N, M, X)
    if ans == INF:ans = -1
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = 10 ** 9 + 100
ans = INF
def dfs(i, S, cost, C_list, A_list, N, M, X):
    global ans
    
    if i == N:
        ok = True
        for j in range(M):
            if S[j] < X:
                ok = False
                break
        if ok:ans = min(ans, cost)
        return
    dfs(i+1, S, cost, C_list, A_list, N, M, X)
    for j in range(M):
        S[j] += A_list[i][j]
    cost += C_list[i]
    dfs(i+1, S, cost, C_list, A_list, N, M, X)
    for j in range(M):
        S[j] -= A_list[i][j]
    cost -= C_list[i]
def main():
    global INF, ans
    N, M, X = map(int, input().split())
    C_list = []
    A_list = []
    for _ in range(N):
        C_A = list(map(int, input().split()))
        C_list.append(C_A[0])
        A_list.append(C_A[1:])
    S = [0 for _ in range(M)]
    cost = 0
    dfs(0, S, cost, C_list, A_list, N, M, X)
    if ans == INF:ans = -1
    print(ans)
if __name__ == "__main__":
    main()

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

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

Solution (Python):

import sys

INF = 10 ** 10


def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    
    ans = INF

    for _ in range(N):
        CA = [int(i) for i in input().split()]
        C.append(CA.pop(0))
        A.append(CA)

    
    for n in range(2 ** N):
        flg = True
        cost = 0
        count = [0] * M
        for i in range(N):
            if n>>i & 1:
                for j in range(M):
                    count[j] += A[i][j]
                cost += C[i]
        
        
        for j in range(M):
            if count[j] < X:
                flg = False
        if flg:
            ans = min(cost, ans)
    print(ans if ans != INF else -1)

if __name__ == '__main__':
    main()

Solution (Python):
N, M, X = map(int, input().split())
books = []
min_cost = float("inf")

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

for i in range(1, 2**N):
    i = format(i, '0{}b'.format(N))
    books_bought = [books[j] for j in range(N) if int(i[j])]
    cost = sum(book[0] for book in books_bought)
    experience = [sum(book[k] for book in books_bought) for k in range(1, len(books_bought[0]))]
    if sum(exp >= X for exp in experience) == M:
        min_cost = min(min_cost, cost)


if min_cost < float("inf"):
    print(min_cost)
else:
    print(-1)

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


bits = [None] * N
ans = float('inf')

def f():
    global X
    global ans

    cost = 0
    algs = [0] * M
    for i in range(N):
        if bits[i]:
            book = A[i]
            cost += book[0]
            for i in range(1, M+1):
                algs[i-1] += book[i]
    
    p = True
    for ai in algs:
        if ai < X:
            p = False

    if p:
        ans = min(ans, cost)

def dfs(v):
    if v >= N:
        f()
        return

    bits[v] = True
    dfs(v+1)

    bits[v] = False
    dfs(v+1)

dfs(0)

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

Solution (Python):

import numpy as np
n, m, x = map(int, input().split())
refer = [list(map(int, input().split())) for _ in range(n)]

ans =[]
for i in range(2**n):
    skill = []
    money = 0

    for j in range(n):
        if (i >> j) & 1:
            skill.append(refer[j][1:])
            money += refer[j][0]
            a = np.array(skill)
            if np.all(np.sum(a, axis=0) >= x):
                ans.append(money)
if ans == []:
    print(-1)
else:
    print(min(ans))

Solution (Python):


def solve():
    import sys
    import numpy as np

    N, M, X = list(map(int, sys.stdin.readline().split()))
    Cs = []
    AAs = []
    for _ in range(N):
        _in = list(map(int, sys.stdin.readline().split()))
        c, As = _in[0], _in[1:]
        Cs.append(c)
        AAs.append(np.array(As))

    ans = float("inf")
    for bit in range(2**N):
        total = 0
        masters = np.array([0]*M)

        for i in range(N):
            if bit>>i&1:
                total += Cs[i]
                masters += AAs[i]

            if sum(masters>=X) == M:
                ans = min(ans, total)

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


if __name__ == "__main__":
    solve()

Solution (Python):
'''
参考
https://kakedashi-engineer.appspot.com/
https://note.com/sdestiny/n/nbd01567e6f7a
bit全探索を行う

※itertools.productについては以下を参照
https://note.nkmk.me/python-itertools-product/
'''
from itertools import product

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:])

INF = 10**9    
ans = INF






for p in product([0, 1], repeat=N):
    skill = [0] * M     
    cost = 0            
    for n in range(N):
        if p[n]:    
            for m in range(M):
                skill[m] += A[n][m] 
            cost += C[n]
    
    if min(skill) >= X:
        ans = min(ans, cost)

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

Solution (Python):

def main():
    import itertools as ite
    import sys, numpy as np
    N,M,X = map(int, sys.stdin.readline().split())
    CA = [np.array(list(map(int, sys.stdin.readline().split()))) for _ in range(N)]
    bit = np.array(list(ite.product([0,1], repeat=N))) 
    
    
    ans = -1
    for row in bit:
        result = np.array([0 for _ in range(M+1)])
        
        for idx, num in enumerate(row):
            
            result += CA[idx]*num
        if np.all(result[1:]>=X):
            
            if ans==-1 or ans >result[0]:
                ans = result[0]
    print(ans)
            
        


if __name__=='__main__':
    main()

Solution (Python):
N, M, X = map(int, input().split())
book = [list(map(int, input().split())) for i in range(N)]
out = 10**12
for i in range(0, 2**N):
    list = [0] * (M+1)
    st = format(int(i), "b").zfill(N)
    for j in range(N):
        if int(st[j]) == 1:
            for a in range(M+1):
                list[a] +=  book[j][a]
            
    if all([b >= X for b in list[1:]]) == True:
        out = min(out, list[0])

if out == 10**12:
    print(-1)

else:
    print(out)

Solution (Python):
import math
import numpy as np

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n,m,x = NextInts()
data = np.array([NextIntList() for i in range(n)], np.int64)

c = data[:,:1].reshape(n)
a = data[:,1:]
ans = 10**10

for i in range(1<<n): 
    now = 1
    point = np.zeros(m, np.int64)
    tmp = 0
    for j in range(n):
        if now&i:
            for k in range(m):
                point[k] += a[j][k]
            tmp += c[j]
        now <<= 1
    ju = True
    for i in range(m):
        if point[i] < x:
            ju = False
            break
    if ju:
        ans = min(ans, tmp)
if ans == 10**10: print(-1)
else: print(ans)

Solution (Python):
N, M, X = map(int, input().split())
D = [list(map(int, input().split())) for i in range(N)]
money = 12 * 10 ** 5 + 1
for i in range(2**N):
    pattern = str(bin(i))[2:]
    und = [0] * M
    mon = 0
    for j in range(len(pattern)):
        if pattern[(-1)*j - 1] == '1':
            mon += D[j][0]
            for k in range(M):
                und[k] += D[j][k + 1]
    for k in range(M):
        if all([l >= X for l in und]):
            money = min(mon, money)
if money == 12 * 10 ** 5 + 1:
    money = -1
print(money)

Solution (Python):
n, m, X = map(int, input().split())
A = [[] for i in range(n)]
c = [0] * n

for i in range(n):
    c_as = list(map(int, input().split()))
    c[i], A[i] = c_as[0], c_as[1:]

INF = 10**9
ans = INF
    
for s in range(0, 1<<n):
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if (s>>i) % 2 == 0: 
            continue
        cost_sum += c[i]
        for j in range(m):
            smart[j] += A[i][j]
    ok = True
    for j in range(m):
        if smart[j] < X:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

if ans == INF:
    ans = -1

print(ans)

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

total = 0
result = 10000000000000000
count = 0
flag = True


for i in range(2 ** N):
    total = 0
    count = 0
    bit = [0]*N
    for j in range(N):
        state = [0] * M
        if (i >> j) & 1:
            bit[j] = 1
    
    
    for k in range(N):
        if bit[k] == 1:
            
            for l in range(M):
                state[l] += c_A[k][l+1]
            total += c_A[k][0]
    
    
    
    for m in range(M):
        if state[m] < X:
            break
        else:
            count += 1
    
    if count == M:
        flag = False
        result = min(total,result)
if flag == False:
    print(result)
else:
    print(-1)

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

min_ = 10**8

costs = []
effects = []

for i in range(n):
  ca = list(map(int, input().split()))
  costs.append(ca[0])
  effects.append(ca[1:])

for i in range(2**n):
  now_cost = 0
  now_effects = [0]*m
  for j in range(n):  
    if ((i >> j) & 1):  
      for k in range(m):
        now_effects[k] += effects[j][k]
      now_cost += costs[j]

  ok=True    
  for k in range(m):
    if now_effects[k] < x:
      ok=False
      break
  if ok:
    min_ = min(min_,now_cost)

if min_ == 10**8:
  print(-1)
  exit()
print(min_)

Solution (Python):
N, M, X = map(int, input().split())
book_lists = [list(map(int, input().split())) for i in range(N)]
max_cost = 10**5*12+1
min_cost = max_cost

for i in range(1, 2**N):
    score_list = [0 for _ in range(M)]
    cost = 0
    for j in range(N):
        if i >> j & 1:
            cost += book_lists[j][0]
            for k in range(M):
                score_list[k] += book_lists[j][k+1]
    if min(score_list) >= X:
        min_cost = min(cost, min_cost)

print(min_cost if not min_cost == max_cost else -1)

Solution (Python):
from sys import stdin, stdout
from collections import deque, defaultdict

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	s = mask
	while s > 0:
		process(s)
		s = (s-1) & mask

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Solution (Python):
from sys import stdin, stdout

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	s = mask
	while s > 0:
		process(s)
		s = (s-1) & mask

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Solution (Python):
from sys import stdin, stdout

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def submasks(m):
	s = m
	while s > 0:
		s = (s-1)&m
		yield s

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	for s in submasks(mask):
		process(s)

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Solution (Python):
from sys import stdin, stdout

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	s = mask
	while s > 0:
		process(s)
		s = (s-1) & mask

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Solution (Python):
import numpy as np
import itertools

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

bit_matrix = itertools.product(range(2), repeat = N)

arr_book_matrix = np.array(book_matrix)
arr_bit_matrix = np.array(list(bit_matrix))

arr_ans_matrix = np.dot(arr_bit_matrix, arr_book_matrix)

ans_matrix = arr_ans_matrix.tolist()

ans = 100000 * 20
for ans_vector in ans_matrix:
    if(min(ans_vector[1:]) >= X):
        ans = min(ans, ans_vector[0])

if(ans == 100000 * 20):
    print(-1)

else:
    print(ans)