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())
k = [list(map(int, input().split())) for i in range(n)]
c = []
for i in range(n):
    c.append(k[i][0])
for i in range(n):
    del k[i][0]

INF = 10**18

ans = INF
for a in range(1<<n):
    cost = 0
    d = [0 for i in range(m)]
    for b in range(n):
        if(a>>b&1):
            cost += c[b]
            for i in range(m):
                d[i] += k[b][i]
    ok = True
    for b in range(m):
        if (d[b] < x):
            ok = False
    if (ok):
        ans = min(ans, cost)
if (ans == INF):
    print (-1)
else:
    print(ans)

Solution (Python):
n, m, x = map(int, input().split())
ca = [tuple(map(int, input().split()))for _ in range(n)]
INF = 10**18
ans = INF
for bit in range(1 << n):
    cost = 0
    proficiency = [0]*m
    for i in range(n):
        if bit >> i & 1:
            c, *A = ca[i]
            cost += c
            for j in range(m):
                proficiency[j] += A[j]
    if cost < ans and all(x <= proficiency[j]for j in range(m)):
        ans = cost
print(ans if ans != INF else -1)

Solution (Python):
from itertools import product
n, m, x = map(int, input().split())
ca = [tuple(map(int, input().split()))for _ in range(n)]
INF = 10**18
ans = INF
for bit in product((0, 1), repeat=n):
    proficiency = [0]*m
    cost = 0
    for i in range(n):
        if bit[i]:
            c, *A = ca[i]
            cost += c
            for j in range(m):
                proficiency[j] += A[j]
    if cost < ans and all(x <= proficiency[j] for j in range(m)):
        ans = cost
print(ans if ans != INF else -1)

Solution (Python):
import sys
from itertools import product
input = sys.stdin.readline
N, M, X = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(N)]
res = -1
for p in product([0, 1], repeat=N):
    sum = [0] * M
    for i in range(N):
        if p[i]:
            for j in range(M):
                sum[j] += grid[i][j + 1]
    if all([sum[j] >= X for j in range(M)]):
        cost = 0
        for i in range(N):
            cost += p[i] * grid[i][0]
        if res == -1:
            res = cost
        else:
            res = min(res, cost)
    else:
        continue
print(res)

Solution (Python):
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(m):
  skill=0
  for j in range(n):
    skill+=l[j][i+1]
  if skill<x:
    print(-1)
    break
else:
  min_total=0
  for i in range(n):
    min_total+=l[i][0]
  for i in range(2**n):
    total=0
    s=[0]*m
    for j in range(n):
      if (i>>j)&1:
        total+=l[j][0]
        for k in range(m):
          s[k]+=l[j][k+1]
    if min(s)>=x:
      if min_total>=total:
        min_total=total
  print(min_total)

Solution (Python):
import itertools

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

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

L = [0, 1]
num = N
bits_list = list(itertools.product(L, repeat=num))

min_cost = float('inf')
for bits in bits_list:

    cost = 0
    understands = [0 for j in range(M)]
    for i in range(N):
        if bits[i] == 1:
            cost += C[i]
            for j in range(M):
                understands[j] += A[i][j]
    
    clear = True
    for u in understands:
        if u < X:
            clear = False
            break
    
    if clear and cost < min_cost:
        min_cost = cost

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

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

N,M,X = MI()
L = LI2(N)
ans = INF
for l in product([0,1],repeat=N):
    know = [0]*M
    cost = 0
    for i in range(N):
        if l[i]==1:
            cost += L[i][0]
            for j in range(M):
                know[j] += L[i][j+1]
    if min(know)<X:
        continue
    ans = min(ans,cost)
if ans==INF:
    print(-1)
else:
    print(ans)

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


books = [ list(map(int,input().split())) for _ in range(n)]
anscost = float('inf')
for choice in choices:
    cost = 0
    learn = [ 0 for _ in range(m)]
    for i in choice:
        book = books[i]
        cost += book[0]
        for j in range(1,m+1):
            learn[j-1] += book[j]
    
    
    
    if min(learn) >= x:
        anscost = min(anscost,cost)
if anscost ==  float('inf'):
    print(-1)
else:
    print(anscost)

Solution (Python):
def __min_cost(idx, cost, studied, costs):
    if idx >= n:
        return
    __min_cost(idx+1, cost, studied, costs)
    cost += cs[idx]
    studied = [s+i for s, i in zip(studied, mat[idx])]
    if all(s >= x for s in studied):
        costs.add(cost)
    else:
        __min_cost(idx+1, cost, studied, costs)

def min_cost():
    costs = set()
    __min_cost(0, 0, [0]*m , costs)
    if len(costs) > 0:
        return min(costs)
    else:
        return -1

n, m, x = map(int, input().split())
mat = []
cs = []
for _ in range(n):
    data = list(map(int, input().split()))
    cs.append(data[0])
    mat.append(data[1:])
print(min_cost())

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

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

ans = 10 ** 21
for b in range(2 ** n):
  A = [0] * m
  c = 0
  for i in range(n):
    if (1 & (b >> i)):
      c += CA[i][0]
      for itr, a in enumerate(CA[i][1:]):
        A[itr] += a
  if all(a >= x for a in A):
    ans = min(ans, c)

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

Solution (Python):
n,m,x=map(int,input().split())
arr=[[0 for i in range(m+1)] for j in range(n)]
b=[0]*18
ans=-1
flag=1
for i in range(n):
    arr[i]=list(map(int,input().split()))
for i in range(2**n):
    b=[0]*18
    for j in range(n):
        flag=1
        if (1& i>>j):
            for s in range(m+1):
                b[s]= b[s]+arr[j][s]
        for y in range(1,m+1):
            if(b[y]<x):
                flag=0
                
        if flag :
            if ans==-1 or ans>b[0]:
                ans=b[0]
print(ans)

Solution (Python):
n, m, x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
import itertools
import numpy as np
from collections import deque

ca = np.array(ca)
bit_all = list(itertools.product(range(2),repeat=n))
ans = deque()

for bit in bit_all:
    bit = bit*(m+1)
    bit = np.array(bit).reshape([m+1,n]).T
    buy =  ca * bit
    buy = list(np.sum(buy,axis=0))
    if min(buy[1:]) >= x:
        ans.append(buy[0])

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

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

min_cost = 1200001
for i in range(2**n):
    cost = 0
    skill = [0 for _ in range(m)]
    for j in range(n):
        if (i>>j) &1 == 1:
            cost += book[j][0]
            for k in range(m):
                skill[k] += book[j][k+1]
    if min(skill) >= x:
        min_cost = min(min_cost, cost)

print('-1' if min_cost == 1200001 else min_cost)

Solution (Python):

import itertools
flg = True
n,m,x = map(int,input().split())
algo = []
tmp = []
for _ in range(n):
    algo.append(list(map(int,input().split())))
    
book = list(itertools.product([0,1],repeat=n))
abi = [0 for _ in range(m)]

for pattern in book:
    
    abi = [0 for _ in range(m)]
    money = 0
    flg = True
    
    for i in range(len(pattern)):
        for j in range(m):
            abi[j] += algo[i][j+1] * pattern[i]
        money += algo[i][0] * pattern[i]
        
    abi_min = [p for p in abi if p < x]
        
    if len(abi_min) != 0:
        flg = False
    if flg:
        tmp.append(money)

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

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

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

INF = 10**9
ans = INF

for s in range(0, 1 << n):
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if (s >> i) % 2 == 0:
            continue
        cost_sum += c[i]
        for j in range(m):
            smart[j] += A[i][j]

    judge = True
    for j in range(m):
        if smart[j] < k:
            judge = False

    if judge:
        ans = min(ans, cost_sum)

if ans == INF:
    ans = -1

print(ans)

Solution (Python):
def __min_cost(idx, cost, studied, costs):
    if idx >= n:
        return
    __min_cost(idx+1, cost, studied, costs)
    cost += cs[idx]
    studied = [s+i for s, i in zip(studied, mat[idx])]
    if all(s >= x for s in studied):
        costs.add(cost)
    __min_cost(idx+1, cost, studied, costs)

def min_cost():
    costs = set()
    __min_cost(0, 0, [0]*m , costs)
    if len(costs) > 0:
        return min(costs)
    else:
        return -1

n, m, x = map(int, input().split())
mat = []
cs = []
for _ in range(n):
    data = list(map(int, input().split()))
    cs.append(data[0])
    mat.append(data[1:])
print(min_cost())

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
import numpy as np

def main():  
    N,M,X = map(int,input().split())
    book = np.array([input().split() for _ in range(N)],np.int32)
    ans = INF
    for bit in range(1<<N):
        ret = np.zeros(M + 1,np.int32)
        for i in range(N):
            if (bit>>i)&1:
                ret += book[i]
        if np.all(ret[1:] >= X):
            ans = min(ans,ret[0])
    print(ans if ans < INF else -1)
if __name__ == '__main__':
    main()

Solution (Python):

import numpy as np
N, M, X = map(int, input().split())
data = np.array([list(map(int, input().split())) for i in range(N)], dtype=np.int64)

prices = data[:, 0]
effects = data[:, 1:]
 
ans_cands = []

for i in range(2 ** N):
    cur_costs = []
    cur_effects = np.zeros(M)
    
    for j in range(N):
        if (i >> j) & 1:
            cur_costs.append(prices[j])
            cur_effects += effects[j, :]

    if np.all(cur_effects >= X):
        ans_cands.append(sum(cur_costs))

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

Solution (Python):
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
INF = 10 ** 9

ans = INF
for i in range(1 << n):
    sm = [0] * m
    cost = 0
    for j in range(n):
        if i >> j & 1:
            cost += ca[j][0]
            for k, e in enumerate(ca[j][1:]):
                sm[k] += e

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

if ans == INF:
    ans = -1

print(ans)

Solution (Python):



import sys


import itertools

def add_lists(a, b):
    result = [0 for i in range(len(a))]
    for i in range(len(a)):
        result[i] = a[i] + b[i]
    return result

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

























INF = float('inf')
ans = INF

for s in range(1<<n):  
    tot = [0 for i in range(m)]  
    now = 0  
    for i in range(n):
        if s >> i & 1:  
            tot = add_lists(tot, a[i])
            now += c[i]
    flag = True
    for i in tot:
        if i < x:
            flag = False
    if flag:
        ans = min(ans, now)

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

Solution (Python):
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:])

ans = 10**9+7

for bit in range(2**N):
    rikai = [0]*M
    money = 0
    for i in range(N):
        if (bit >> i) & 1 == 1:
            for j in range(M):
                rikai[j] += A[i][j]
            money += C[i]
    if min(rikai) >= X:
        ans = min(ans,money)
        
if ans == 10**9+7:
    print(-1)
else:
    print(ans)

Solution (Python):
from itertools import product
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for i in range(n)]
INF = 10**12

ans = INF
l = [0, 1]
for v in product(l, repeat=n):
    rikai = [0 for _ in range(m)]
    cost = 0
    for i in range(n):
        if v[i]:
            c = ca[i][0]
            a = ca[i][1:]
            cost += c
            for j in range(m):
                rikai[j] += a[j]
    f = True
    for i in range(m):
        if rikai[i] < x:
            f = False
    if f:
        ans = min(ans, cost)
if ans == INF:
    print(-1)
else:
    print(ans)

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

min_cost = float('inf')
 
for i in range(2**len(book_list)):  
    
    cost = 0
    score_list = [0 for _ in range(m)]
    for j in range(len(book_list)):
        if (i >> j) &1 == 1:
            cost += book_list[j][0]
            for idx in range(m):
                score_list[idx] += book_list[j][idx+1]
    if min(score_list) >= x:
        min_cost = min(min_cost,cost)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

import numpy as np
from itertools import product

n, m, x = map(int, readline().split())
ca = np.array(read().split(), np.int64).reshape((n, m + 1))
INF = 10 ** 9

c = ca[:, 0]
a = ca[:, 1:]

p = np.array([e for e in product([1, 0], repeat=n)], np.int64)
rikai = np.dot(p, a)
cost = np.dot(p, c)
idx = rikai.min(axis=1) >= x
if idx.any():
    ans = cost[idx].min()
else:
    ans = -1

print(ans)

Solution (Python):
n, m, x = map(int, input().split())
ca_list = []
for i in range(n):
    ca_list.append(list(map(int, input().split())))
ans = 10**10
    
for i in range(2**n):
    suml = [0]*m
    money = 0
    for j in range(n):
        if i>>j&1:
            for k in range(1, m+1):
                suml[k-1] += ca_list[j][k]
            money += ca_list[j][0]
    ok = 1
    for a in range(m):
        if suml[a] < x:
            ok =0
            break
    if ok:
        ans = min(ans, money)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

import numpy as np
from itertools import product

n, m, x = map(int, readline().split())
ca = np.array(read().split(), np.int64).reshape((n, m + 1))
INF = 10 ** 9

c = ca[:, 0]
a = ca[:, 1:].T

ans = INF
for p_li in product([1, 0], repeat=n):
    p = np.array(p_li)
    rikai = a * p
    sm = rikai.sum(axis=1)
    if sm.min() >= x:
        cost = (c * p).sum()
        ans = min(ans, cost)

if ans == INF:
    ans = -1

print(ans)

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

ans = float('inf')
flg = False
for i in range(1<<n):
    und = [0 for _ in range(m)]
    price = 0
    for j in range(n):
        if (i >> j) & 1:
            for k in range(m):
                und[k] += cl[j][k+1]
            price += cl[j][0]
    und = [1 if i >= x else 0 for i in und]
                
    if all(und):
        flg = True
        ans = min(ans,price)
        
print(ans if flg else '-1')

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import product
def main():
    n,m,x=map(int,input().split())
    CA=[[int(_) for _ in input().split()] for i in range(n)]
    ans=10**10
    n_lis=list(product([True,False],repeat=n))
    for comb in n_lis:
        cunt=0
        A=[0]*m
        for i,ca in enumerate(CA):
            if comb[i]:
                cunt+=ca[0]
                for j,aa in enumerate(ca[1:]):
                    A[j]+=aa
        for a in A:
            if a<x:
                break
        else:
            ans=min(ans,cunt)
    if ans==10**10:
        print(-1)
    else:
        print(ans)

if __name__=='__main__':
    main()

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

costmin=float('inf')
for k in range(2**N):
  tansaku=k
  koubai=[0 for i in range(N)]
  rikaido=[0 for i in range(M)]
  cost=0
  for i in range(N-1):
    koubai[i]=tansaku//(2**(N-i-1))
    tansaku=tansaku%(2**(N-i-1))
  koubai[-1]=tansaku
  for i in range(N):
    if koubai[i]==1:
      cost+=C[i]
      for j in range(M):
        rikaido[j]+=A[i][j]
  for i in range(M):
    if rikaido[i]<X:
      break
  else:
    costmin=min(costmin,cost)
if costmin!=float('inf'):
  print(costmin)
else:
  print(-1)

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

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


def calcPoint(point, n):
    for i in range(m):
        point[i] += a[n][i+1]
    return point


def judgePoint(point):
    for i in range(m):
        if point[i] < x:
            return False
    return True


ans = []
for i in range(2**n):  
    buy = []
    for j in range(n):  
        if((i >> j) & 1):  
            buy.append(1)
        else:
            buy.append(0)
    price = 0
    point = [0]*m
    for i in range(n):
        if buy[i] == 1:
            calcPoint(point, i)
            price += a[i][0]
    if judgePoint(point):
        ans.append(price)
if len(ans) == 0:
    print(-1)
else:
    print(min(ans))

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
import numpy as np



def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    INF = 10 ** 10
    ans = INF
    for i in range(N):
        lists = [int(c) for c in input().split()]
        ci = lists[0]
        ai = lists[1:]
        C.append(ci)
        A.append(ai)


    for i in range(1 << N):
        ability = np.zeros((M, ))
        cost = 0
        for j in range(N):
            if (i >> j) & 1:
                ability += np.array(A[j])
                cost += C[j]
        if sum(ability >= X) == M:
            ans = min(ans, cost)

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

    
    



if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import numpy as np

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


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


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


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

  
print(value)

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

ans = 10 ** 18
for i in range(2 ** N):
    cost = 0
    each_alg = [0 for _ in range(M)]
    for j in range(N):
        if (i >> j) & 1:
            cost += CA[j][0]
            for k in range(M):
                each_alg[k] += CA[j][k+1]
    if min(each_alg) >= X:
        ans = min(ans, cost)

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

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

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

result = -1
for i in range(1 << N):
    t = [0] * M
    c = 0
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)

Solution (Python):
from itertools import product

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

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

result = -1
for p in product([True, False], repeat = N):
    t = [0] * M
    c = 0
    for j in range(N):
        if not p[j]:
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)

Solution (Python):
import numpy as np

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


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


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


for i in range(1,2 ** n):
  
  slist=np.right_shift(i,np.arange(n))
  blist=np.bitwise_and(slist,1).tolist()
  selects=list(map(bool,blist))
  
  

  picks=np.sum(table[selects,:],axis=0)
  if not boolAchieve(picks):
    continue
  value=min(value,picks[0])

  
print(value)

Solution (Python):
import numpy as np

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


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


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


for i in range(1,2 ** n):
  slist=np.right_shift(i,np.arange(n))
  blist=np.bitwise_and(slist,1).tolist()
  selects=list(map(bool,blist))
  
  picks=np.sum(table[selects,:],axis=0)
  if not boolAchieve(picks):
    continue
  value=min(value,picks[0])

  
print(value)

Solution (Python):
from itertools import product
n,m,x=map(int,input().split())
c=[0]*n
a=[0]*n
INF=10**9
for i in range(n):
  d,*b=map(int,input().split())
  c[i]=d
  a[i]=b
ans=INF
for z in product([0,1],repeat=n):
  u=[0]*m
  cost=0
  for i in range(n):
    cost+=c[i]*z[i]
    for j in range(m):
      u[j]+=a[i][j]*z[i]
  flg=True
  for j in range(m):
    if u[j]<x:
      flg=False
  if flg:
    ans=min(ans,cost)
if ans==INF:
  ans=-1
print(ans)

Solution (Python):
n, m, x = [int(e) for e in input().split()]

import numpy as np
import itertools

all = np.zeros(n*(m+1)).reshape(n,m+1)

for i in range(n):
    all[i] += [int(e) for e in input().split()]

b = itertools.product([True,False],repeat=n)

dp=10**10

for i in b:
    i = np.array(i)
    if (all[i][:,1:].sum(axis = 0) >=x).all() :
        dp = min(dp,all[i][:,0].sum(axis = 0))

if dp ==10**10:
    dp = -1
print(int(dp))

Solution (Python):
n, m, x = [int(e) for e in input().split()]

import numpy as np

all = np.zeros(n*(m+1)).reshape(n,m+1)

for i in range(n):
    all[i] += [int(e) for e in input().split()]

bool_list = np.array([])
a = []
b = []
def make(n):
    if len(a) == n:
        b.append([0 for _ in range(n)])
        for i,v in enumerate(a) :
            if v == True:
                b[-1][i] = True
            else:
                b[-1][i] = False
    else:
        for i in [True,False]:
            a.append(i)
            make(n)
            a.pop()

make(n)
c=np.array(b)

dp=10**10

for i in c:
    if (all[i][:,1:].sum(axis = 0) >=x).all() :
        dp = min(dp,all[i][:,0].sum(axis = 0))

if dp ==10**10:
    dp = -1
print(int(dp))

Solution (Python):
def MI(): return map(int, input().split())
def LI(): return list(MI())
if __name__ == "__main__":
    N, M, X = MI()
    C = [LI() for _ in range(N)]
    ans = float('inf')
    for i in range(1<<N):
        score = [0] * M
        money = 0
        for j in range(N):
            if (1<<j) & i != 0:
                money += C[j][0]
                for k in range(M):
                    score[k] += C[j][k+1]
        if min(score) >= X:
            ans = min(ans, money)
    print(ans if ans != float('inf') else -1)

Solution (Python):




















from itertools import combinations
from operator import itemgetter

def get_min_price(N, M, X, C_i, A_i):
    combs = []
    min_price = 0

    for i in range(N+1):
        for comb in combinations(list(range(N)), i):
            price = sum([C_i[j] for j in comb])
            combs.append((price, comb))
    
    

    for price, comb in sorted(combs, key=itemgetter(0)):
        scores = [0] * M
        
        for j in comb:
            for k in range(M):
                scores[k] += A_i[j][k]
            
            if all(list(map(lambda score: score >= X, scores))):
                return price

            

    return -1


if __name__ == '__main__':
    N, M, X = map(int, input().split())
    C_i, A_i = [], []
    for i in range(N):
        temp = list(map(int, input().split()))
        
        C_i.append(temp[0])
        A_i.append(temp[1:])
    res = get_min_price(N, M, X, C_i, A_i)
    print(res)

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

c = []
d = []
for i in range(n):
	s = list(map(int, input().split()))
	d.append(s)
ans = 10**9
for i in range(1,n+1):
	for j in itertools.combinations(d,i):
		s = [0 for ii in range(m+1)]
		for k in j:
			for l in range(m+1):
				s[l] += k[l]
		y = min(s[1:])
		if y >= x:
			ans = min(ans,s[0])
if ans == 10**9:
	print (-1)
else:
	print (ans)

Solution (Python):
n,m,x=map(int,input().split())
book=[list(i for i in map(int,input().split()))for _ in range(n)]
t=[0]
def dfs(seq, seq2, c):
  judgeSeq(calSkills(seq), c) 
  if len(seq2)==0: return 
  for i in range(len(seq2)):
    seq.append(seq2[i])
    dfs(seq, seq2[i+1:], c)
    seq.pop()

def calSkills(seq):
  res = [0]*(m+1)
  for i in seq:
    for j in range(m+1):
      res[j] += book[i][j]
  return res

def judgeSeq(skills, c):
  if all(x<=i for i in skills[1:]):
    t[0]+=1
    c[0] = min(c[0], skills[0])

if __name__ == "__main__":
  c = [sum(book[i][0] for i in range(n))]
  dfs([], [i for i in range(n)], c)
  print(c[0] if t[0]>0 else -1)

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

Solution (Python):
import numpy as np

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


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


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


for i in range(1,2 ** n):
  selects=[bool((i >> j) & 1) for j in range(n)]
  picks=np.sum(table[selects,:],axis=0)
  if not boolAchieve(picks):
    continue
  value=min(value,picks[0])

  
print(value)

Solution (Python):
def C():
    N, M, X = map(int, input().split())
    C = []
    A = []
    for i in range(N):
        temp = [int(n) for n in input().split()]
        C.append(temp[0])
        A.append(temp[1:])
    
    ans = [float('inf')]
    def helper(i, skills, cost):
        if i == N:
            for s in skills:
                if s < X:
                    return
            ans[0] = min(ans[0], cost)
            return
        helper(i+1, [skills[j]+A[i][j] for j in range(M)], cost+C[i])
        helper(i+1, skills, cost)

    for i in range(N):
        helper(i, [0]*M, 0)
    
    if ans == [float('inf')]:
        print(-1)
        return
    print(ans[0])
C()

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

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

ans = 10**12
for i in range(1<<n):
    rikai  = [0] * m
    cost = 0
    for j in range(n):
        if i&(1<<j):
            
            cost += C[j]
            for k in range(m):
                rikai[k] += A[j][k]            
    a = sum([1 for r in rikai if r >= x])
    if a == m:
        ans = min(ans,cost)
print(ans if ans != 10**12 else -1)

Solution (Python):







INF = float("inf")
import sys,collections

N,M,X = map(int,sys.stdin.readline().split())

C = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) 

ALL = [0]*(M+1)
for a in C:
    for i in range(M+1):
        ALL[i] += a[i]

if any(e < X for e in ALL[1:]):
    print(-1)
    exit()

m = INF
def backtrack(n,c):
    
    if n == N:
        if all(a >= X for a in c[1:]):
            
            global m
            m = min(m,c[0])
        return
    backtrack(n+1,c)
    backtrack(n+1,[a+b for a,b in zip(c,C[n])])

backtrack(0,[0]*(M+1))
print(m)

Solution (Python):
n, m, x = map(int, input().split())
a = []
c = 2000000
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(2**n):
    b = [0]*(m+1)
    for j in range(n):
        if i%2 == 1:
            for k in range(m+1):
                b[k] += a[j][k]
        i //= 2
    d = 0
    for j in range(m):
        if b[j+1] < x:
            d += 1
    if d == 0:
        c = min(c, b[0])
if c == 2000000:
    c =-1
print(c)