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 itertools
from operator import add
n,m,x = map(int,input().split())
li = []
money=100000000
for i in range(n):
	li.append(list(map(int,input().split())))

for i in range(1, n+1, 1):
	for v in itertools.combinations(li, i):
		sum_li = [0]*(m+1)
		for j in v:
			sum_li = [x+y for (x, y) in zip(sum_li,j)]
		for j in range(m):
			if(sum_li[j+1] < x):
				break
		else:
			money = min(sum_li[0], money)

print(money if(money != 100000000) else -1)

Solution (Python):
from itertools import product
N, M, X = map(int, input().split())

val0 = [0]*(M+1)
ans = 10**9
val = []
for _ in range(N):
    val.append(list(map(int, input().split())))

for i in range(2**N):
    ls = ["+"]*N
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = "-"
    for m, n in enumerate(ls):
        if n == '+':
            val0 = [x + y for (x, y) in zip(val0, val[m])]
    if ans > val0[0]:
        for k, l in enumerate(val0[1:]):
            if l < X:
                break
            elif k == len(val0[1:])-1:
                ans = val0[0]
    val0 = [0]*(M+1)
        
if ans == 10**9:
    print(-1)
else:
    print(ans)

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

ans = 10**10
for bit in range(1 << n):
    score_sum = [0 for _ in range(m)]
    price_sum = 0
    for i in range(n):
        if ((bit >> i) & 1) == 1:
            price_sum += price[i]
            for j in range(m):
                score_sum[j] += book[i][j]
    flag = True
    for v in score_sum:
        if v < x:
            flag = False
    if flag:
        ans = min(ans, price_sum)

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

Solution (Python):
from operator import add

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

book_list = []
check = {}

for i in range(N):
    book_list.append(input().split(' '))


def search_min_cost(cost, skill, i):

    
    if all([x >= X for x in skill]):
        return cost

    
    if len(book_list) == i:
        return -1

    book = book_list[i]

    book_cost = int(book[0])
    book_skill = list(map(int, book[1:]))

    
    use_skill = list(map(add, skill, book_skill))
    use_cost = search_min_cost(cost + book_cost, use_skill, i + 1)

    
    no_use_cost = search_min_cost(cost, skill, i+1)

    if use_cost == -1:
        return no_use_cost

    if no_use_cost == -1:
        return use_cost

    if use_cost > no_use_cost:
        return no_use_cost

    return use_cost


cost = search_min_cost(0, [0] * M, 0)
print(cost)

Solution (Python):
a,b,c=map(int,input().split())
d=[]
for i in range(a):
    n=list(map(int,input().split()))
    d.append(n)
ans=[]
q=len(d)
for i in range(2**q):
    score=[0]*b
    total=0
    n=0
    for j in range(q):
        if ((i>>j)&1):
            for m in range(b):
                score[m]+=d[j][m+1]
            total+=d[j][0]
    for mm in range(b):
        if score[mm]>=c:
            n+=1
    if n==b:
        ans.append(total)

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

Solution (Python):
def check(idxs_):
    rikaido = [0 for i in range(m)]
    cost_ = 0
    for i in idxs_:
        for j in range(m):
            rikaido[j] += a[i][j]
        cost_ += c[i]
    for i in range(m):
        if rikaido[i] < x:
            cost_ = 9999999
    return cost_


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

mini = 9999999

for i in range(2 ** n):
    _ = []
    for j in range(n):
        if ((i >> j) & 1):
            _.append(j)
    cost = check(_)
    if cost < mini:
        mini = cost
    

if mini == 9999999:
    mini = -1

print(mini)

Solution (Python):
def main():
    n,m,x = map(int,input().split())
    a = [[] for _ in range(n)]
    c = [0] * n

    INF = 10 ** 9
    ans = INF

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

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

if __name__ == "__main__":
    main()

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

ans = -1

for i in range(1<<n):
    csum = 0
    mlst = [0]*m
    for j in range(n):
        if (i>>j)&1==1:
            csum += c[j]
            for k in range(m):
                mlst[k]+=a[j][k]
    if all(X >= x for X in mlst):
        if ans == -1:
            ans = csum
        else:
            ans = min(ans,csum)

print(ans)

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

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

ans = 1e20
for i in range(2**N):
    cost = 0
    vals = [0] * M
    for j in range(N):
        if (i >> j & 1) == 1:
            cost += C[j]
            vals = [vals[k] + A[j][k] for k in range(M)]
    if min(vals) >= X and cost <= ans:
        ans = cost 

if ans == 1e20:
    ans = -1

print(ans)

Solution (Python):
import itertools

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

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

ANS = 10**9

for i in it:
    arr = [0]*(M+1)
    for j in range(N):
        arr = list(map(lambda x,y: x+y*i[j], arr, l[j]))
    if all([k>=X for k in arr[1:]]):
        ANS = min(ANS,arr[0])
if ANS == 10**9:
    ANS = -1
print(ANS)

Solution (Python):
import itertools
n,m,x =map(int,input().split())
lists=[]
understand=[0]*m
num= [0,1]
ans = 10**10000
patterns = list(itertools.product(num, repeat=n))
for i in range(n):
    lists.append(list(map(int,input().split())))
total =0

for i in patterns:
    pattern = list(i)
    total =0
    understand=[0]*m
    for l in range(n):
        if pattern[l] ==1:
            total += lists[l][0]
            for k in range(m):
                understand[k] += lists[l][k+1]
    understand.sort()
    if understand[0] >= x:
        ans = min(ans,total)
if ans == 10**10000:
    print(-1)
else:
    print(ans)

Solution (Python):
N, M, X = map(int, input().split())
lst = [[int(x) for x in input().split()] for _ in range(N)]
ret = 100 ** 100
for mask in range(2 ** N):
    C = [0] * M
    cst = 0
    for i in range(N):
        if (mask >> i) & 1:
            cst += lst[i][0]
            for j in range(1, M + 1):
                C[j - 1] += lst[i][j]
    if min(C) >= X:
        ret = min(ret, cst)
if ret < 100 ** 100:
    print(ret)
else:
    print(-1)

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

ans = float("inf")
for bit in range(1 << n):
    rikai = [0 for i in range(m)]
    count = 0

    for i in range(n):
        if bit & (1 << i):
            for j in range(m):
                rikai[j] += a[i][j]
            count += c[i]

    flag = True
    for i in rikai:
        if i < x:
            flag = False
            break

    if flag:
        ans = min(ans, count)

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

Solution (Python):
from itertools import combinations as comb

n,m,x=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(n)]
smmin=None
for j in range(1,n+1):
    for z in comb(range(1,n+1),j):
        und=[0 for i in range(m)]
        sm=0
        for l in range(j):
            sm+=lst[z[l]-1][0]
            for k in range(1,m+1):
                und[k-1]+=lst[z[l]-1][k]
        for y in und:
            if y<x: break
        else :
            if not smmin: smmin=sm
            elif smmin>sm: smmin=sm
if not smmin: print(-1)
else : print(smmin)

Solution (Python):
from numpy import sort

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

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

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

Solution (Python):
from numpy import cumsum

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

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

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

Solution (Python):
import collections

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

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

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

Solution (Python):
from itertools import combinations
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = 10**9
for i in range(1, n+1):
  for j in combinations(ca, i):
    t = [0]*(m+1)
    for k in j:
      for l in range(m+1):
        t[l] += k[l]
    if all(t[a] >= x for a in range(1,m+1)):
      ans = min(ans, t[0])
if ans != 10**9:
  print(ans)
else:
  print(-1)

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



ans = 10**10

for i in range(1 << n):
    money = 0
    understand = [0]*m

    for j in range(n):
        if (i >> j) & 1 == 0:
            continue
        money += c[j]
        for k in range(m):
            understand[k] += a[j][k]
    for l in range(m):
        if understand[l] < x:
            break
    else:
        ans = min(ans, money)


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

Solution (Python):
import itertools

n, m, x = map(int,input().split())
all_list = [0] * n
for i in range(n):
    all_list[i] = list(map(int,input().split()))

prices = []

for r in range(n):
    for tup in (map(list,itertools.combinations(all_list, r+1))):
        sum = [0] * (m+1)
        for lis in tup:
            for i, val in enumerate(lis):
                sum[i] += val
        for i in range(m):
            if sum[i+1] < x:
                break
        else:
            prices.append(sum[0])

if prices:
    print(min(prices))
else:
    print(-1)

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

for i in range(2 ** n):
    cost = 0
    skills = [0] * m
    for j in range(n):
        if ((i >> j) & 1):
            cost += k[j][0]
            for s, t in enumerate(k[j][1:]):
                skills[s] += t
            if all(map(lambda skill: skill >= x, skills)):
                ans = min(ans, cost)
print(-1 if ans == 10 ** 9 else ans)

Solution (Python):
import numpy as np

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

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

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

Solution (Python):
def resolve():
	(N, M, X), *T = [[*map(int, i.split())] for i in open(0)]
	ans = []
	for i in range(1, 2**N):
		tmp = []
		for j in range(N):
			if i>>j & 1 == 1:
				tmp.append(T[j])
		c, *a = map(sum, zip(*tmp))
		if min(a) >= X:
			ans.append(c)
	if ans:
		print(min(ans))
	else:
		print(-1)
resolve()

Solution (Python):
import itertools

N,M,X= (int(x) for x in input().split(' '))
all_book =[]
min_price = 10**5*12 +1
c_lst = []
for i in range(N):
    book_lst= [int(x) for x in input().split(' ')]
    all_book.append(book_lst)
for k in range(1,N+1):
    for m in itertools.combinations(all_book, k):
        if len(m) > 1:
            combined1 = [i*0 for i in range(M+1)]
            for i in range(len(m)):
                combined1 = [x + y for (x, y) in zip(combined1, m[i])]
            c_lst.append(combined1)
        elif len(m) == 1:
            c_lst.append(m[0])
for l in range(len(c_lst)):
    if min(c_lst[l][1:M+1]) >= X:
        if min_price > c_lst[l][0]:
            min_price = c_lst[l][0]
if min_price == 10**5*12 +1:
    min_price = -1

print(min_price)

Solution (Python):
import numpy as np
import itertools

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

all_df = np.zeros((1,M+1))
for n in range(N):
  A = [int(i) for i in input().split()]
  all_df = np.vstack([all_df, np.array(A).reshape(1,-1)])
all_df = all_df[1:]

cost = N * (10**6)
for pattern in itertools.product([0,1], repeat=N):
  result = all_df[np.array(pattern).astype(bool)].sum(axis=0)

  if (X > result[1:]).sum() > 0:
    pass
  else:
    if result[0] < cost:
      cost = result[0]

if cost == N * (10**6):
  print(-1)
else:
  print(int(cost))

Solution (Python):
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
price = []
for i in range(2 ** n):
    cnt = [0]*m
    price_temp = 0
    for j in range(n):
        if (i >> j) & 1:
            price_temp += c[j][0]
            for k in range(m):
                cnt[k] += c[j][k+1]
    if all(s >= x for s in cnt):
        price.append(price_temp)
print(min(price) if len(price) > 0 else -1)

Solution (Python):
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for i in range(N)]
kotae=[]
def saiki(A):
    if len(A)==N:
        goukei=[0]*M
        onedan=0
        for i in range(N):
            if A[i]==1:
                for j in range(M):
                    goukei[j]+=CA[i][j+1]
                onedan+=CA[i][0]
        
        if min(goukei)>=X:
            kotae.append(onedan)
        return
    for i in range(2):
        A.append(i)
        saiki(A)
        A.pop()
saiki([])
if len(kotae)==0:
    print(-1)
    exit()
print(min(kotae))

Solution (Python):
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for i in range(N)]
kotae=[]
def saiki(A):
    if len(A)==N:
        goukei=[0]*M
        onedan=0
        for i in range(N):
            if A[i]==1:
                for j in range(M):
                    goukei[j]+=CA[i][j+1]
                onedan+=CA[i][0]
        
        if min(goukei)>=X:
            kotae.append(onedan)
        return
    for i in range(2):
        A.append(i)
        saiki(A)
        A.pop()
saiki([])
if len(kotae)==0:
    print(-1)
    exit()
print(min(kotae))

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

ans = 99999999

for i in range(2 ** n):
    bag = []
    for j in range(n):  
        if (i >> j) & 1:
            bag.append(l[j])
    skill = [0] * m
    enough = [0] * m  
    cost = 0
    for sub in bag:
        cost += sub[0]
        for kk in range(1, m+1):
            skill[kk - 1] += sub[kk]
            if skill[kk - 1] >= x:
                enough[kk - 1] += 1
    if 0 not in enough:  
        if ans > cost:
            ans = cost  
if ans == 99999999:  
    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(z >= x for z in t):
    if result == -1:
      result = c
    else:
      result = min(result, c)
print(result)

Solution (Python):


def main():
    N, M, X = map(int, input().split())
    mat = [list(map(int, input().split())) for _ in range(N)]

    flag = False
    ans = 10 ** 18

    for i in range(1<<N):
        tmp = [0] * (M+1)
        mflag = True
        for j in range(N):
            if (i>>j)&1:
                tmp = [x+y for x, y in zip(tmp, mat[j])]
        for k in range(M):
            if tmp[1+k] < X:
                mflag = False
                break
        if mflag and tmp[0] < ans:
            ans = tmp[0]
            flag = True
    print(ans) if flag else print('-1')

if __name__ == '__main__':
    main()

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


result = -1
for i in range(2**n):
  skill = [0]*m
  cost = 0
  for j in range(n):
    if (i >> j) & 1 == 0:
      continue
    cost += c[j]
    for s in range(m):
      skill[s] += a[j][s]

  if all(s >= x for s in skill):
    if result == -1:
      result = cost
    else:
      result = min(result,cost)
print(result)

Solution (Python):
from itertools import product
import numpy as np
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
a,c=np.array([i[1:] for i in ca]).T,np.array([i[0] for i in ca])
ans=pow(10,9)
for i in product([0,1],repeat=n):
  i=np.array(i)
  if all(np.dot(a,i)>=x):
    s=np.dot(i,c)
    ans=s if s<ans else ans
print(ans if ans<pow(10,9) else -1)

Solution (Python):
N, M, X = map(int, input().split())
sankosho = []
for n in range(N):
    input_data = list(map(int, input().split()))
    sankosho.append(input_data)
for j in range(1, M+1):
    summed = 0
    for i in range(N):
        summed += sankosho[i][j]
    if summed < X:
        print(-1)
        exit()
ans_opt = []
for bit in range(2**N):
    cost = 0
    gain = []
    for i in range(N):
        if ((bit >> i) & 1):
            cost += sankosho[i][0]
            for j in range(1, M+1):
                if len(gain) <= j-1:
                    gain.append(sankosho[i][j])
                else:
                    gain[j-1] += sankosho[i][j]
    if not(len(gain) == 0):
        if min(gain) >= X:
            ans_opt.append(cost)
print(min(ans_opt))

Solution (Python):

N,M,X = map(int,input().split())
cost_performances = []
for i in range(N):
  book = list(map(int,input().split()))
  cost_performances.append(book)
  for j in range(len(cost_performances)-1):
    cost_performances.append([book[k]+cost_performances[j][k] for k in range(M+1)])
candidate = []
for cost_performance in cost_performances:
  judge = [cost_performance[i+1]>=X for i in range(M)]
  if(False in judge):
    continue
  else:
    candidate.append(cost_performance)
if(len(candidate)==0):
  print(-1)
else:
  cost = [candidate[i][0] for i in range(len(candidate))]
  print(min(cost))

Solution (Python):
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

a,b,c=ml()
cost=[]
for i in range(a):
    cost.append(ll())
ans=1e18    
flag=1
for i in range(1<<a):
    val=[0]*(b+1)
    for j in range(a):
        if(i&(1<<j)):
            for k in range(b+1):
                val[k]+=cost[j][k]    
    f=0
    for j in val[1:]:            
        if(j<c):
            f=1
            break
    if f==0:
        flag=0
        ans=min(val[0],ans)
if(flag):
    print(-1)
else:    
    print(ans)

Solution (Python):
import sys 
from collections import deque
import numpy as np
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def Main():
    n,m,x = IL()
    table = np.zeros(m,dtype=int)
    c = deque()
    a = deque()
    for _ in range(n):
        tmp = deque(LI())
        c.append(tmp.popleft())
        a.append(tmp)

    ans = -1
    for bit in range(2**n):
        tmp = 0
        buff = np.zeros_like(table)
        for i in range(n):
            if (bit>>i)&1:
                tmp += c[i]
                buff += a[i]
        if np.all(buff>=x):
            if ans==-1 or tmp<ans:
                ans = tmp
    print(ans)
    return

if __name__=='__main__':
    Main()

Solution (Python):
import numpy as np

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

min_C = np.inf
conbi = None
m = 2**N

for i in range(m):
  tmp = []
  for _ in range(N):
    tmp.append(i%2)
    i //= 2
  
  sum_array = np.sum(array[np.where(tmp)], axis=0)
  
  if np.all(sum_array[1:]>=X):
    if sum_array[0] < min_C:
      min_C = sum_array[0]
      conbi = tmp
      
if conbi is None:
  print(-1)
else:
  print(min_C)

Solution (Python):
n,m,x = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
p = 12*(10**5)+1
for i in range(2**n):
    di= [0]*(m+1)
    for j in range(n):
        if (i>>j)&1:
            for k in range(m+1):
                di[k] += ls[j][k]
    for l in range(1,m+1):
        if di[l] < x:
            break
    else:
        if p > di[0]:
            p = di[0]
if p <= 12*(10**5):
    print(p)
else:
    print(-1)

Solution (Python):
import itertools

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

ans = []

for s in itertools.product(range(2), repeat=N):

    li = [0 for _ in range(M)]
    cum = 0
    for i, v in enumerate(s):
        if v == 1:
            ca = CA[i]
            cum += ca[0]

            for j, x in enumerate(ca[1:]):
                li[j] += x

        q = [p >= X for p in li]
        if all(q):
            ans.append(cum)

print(min(ans) if ans else -1)

Solution (Python):

"""
Created on Mon Jun 15 11:10:31 2020

@author: asaka
"""

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

for n in range(N):
    temp = list(map(int, input().split()))
    C.append(temp[0])
    A.append(temp[1:])
    
for i in range(2**N):
    mny = 0
    score = [0]*M
    for j in range(N):
        if i&(2**j)>0:
            mny += C[j]
            for k in range(M):
                score[k] += A[j][k]
    if min(score)>=X:
        ans = min(ans, mny)

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

Solution (Python):
n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for x in range(n)]
total = [0]*(m+1)
flg = False
mflg = True
min_num = 100100100100100
for i in range(1,2**n):
    for j in range(n):
        if ((i >> j) & 1):
            total = [x + y for (x, y) in zip(a[j], total)]
    for k in range(m):
        if total[1+k] < x:
            mflg = False
            break
    if mflg and total[0] < min_num:
        min_num = total[0]
        flg = True
    total = [0]*(m+1)
    mflg = True
if flg:
    print(min_num)
else:
    print('-1')

Solution (Python):
N,M,X = map(int,input().split())
li = []
import numpy as np
C = []

for _ in range(N):
    c,*a = map(int,input().split())
    li.append(np.array(a))
    C.append(c)

counter = []

for i in range(1<<N):
    skill_li = np.zeros(M).astype(int)
    sum_price = 0
    for k in range(N):
        if (i>>k) & 1:
            skill_li += li[k]
            sum_price += C[k]
    if all(skill_li>=X):
        counter.append(sum_price)

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

Solution (Python):


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

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

ans = -1


for i in range(2**N):
  skill = [0] * M
  money = 0
  for j in range(N):  
    if ((i >> j) & 1):  
      
      money += temp[j][0]
      for k in range(M):
        skill[k] += temp[j][k+1]
  
  if min(skill) >= X:
    if ans == -1:
      ans = money
    else:
      ans= min(money,ans)

print(ans)

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

if min(p) < x:
  ans = -1
else:
  l = [0, 1]
  buy = list(itertools.product(l, repeat=n))
  point = []
  price = []
  for  i in range(len(buy)):
    result = [0] * m
    k = 0
    for j in range(n):
      result += np.array(a[j]) * buy[i][j]
      k += c[j] * buy[i][j]
    if min(result) >= x:
      point.append(result)
      price.append(k)
  ans = min(price)
print(ans)

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

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

ans = 10 ** 10

for i in range(2**N):
    tmp = [0]*M
    tmp2 = 0
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                tmp[k] += l[j][k+1]
            tmp2 += l[j][0]
    flag = True
    for k in range(M):
        if tmp[k] < X:
            flag = False
    if flag:
        ans = min(ans, tmp2)
if ans != 10**10:
    print(ans)
else:
    print(-1)

Solution (Python):
N,M,X = map(int,input().split())
C=[0 for i in range(N)]
A=[[] for i in range(N)]
min_cost=10000000000
for i in range(N):
    C[i],*A[i]=map(int,input().split())
for i in range(1<<N):
    L=[0 for i in range(M)]
    cost=0
    for j in range(N):
        if 1&(i>>j):
            for k in range(M):
                L[k]+=A[j][k]
            cost+=C[j]
    if min(L)>=X:
      min_cost=min(min_cost,cost)
if min_cost==10000000000:
  print(-1)
else:
  print(min_cost)

Solution (Python):
N, M, X = map(int, input().split())
C = [0] * N
A = [[0] * M] * N
price_min = float('inf')

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

for i in range(2 ** N):
    is_read = [True] * N
    price = 0
    skill = [0] * M

    for j in range(N):
        if((i >> j) & 1):
            is_read[j] = False

    for k in range(N):
        if is_read[k] == True:
            price += C[k]

            for l in range(M):
                skill[l] += A[k][l]

    if min(skill) >= X:
        price_min = min(price_min, price)

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

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

ans = 1001001001
for s in range(2 ** n):
    C = [0] * m
    cost = 0
    for i in range(n):
        if (s >> i) & 1:
            cost += A[i][0]
            for j in range(m):
                C[j] += A[i][j+1]
        ok = True
        for c in C:
            if c < x:
                ok = False
                break
        if ok:
            ans = min(ans, cost)
 
if ans == 1001001001:
    print(-1)
else:
    print(ans)

Solution (Python):
n,m,x=map(int,input().split())
A=[]
for _ in range(n):
  A.append(list(map(int,input().split()))) 
yeen=[]  
for i in range(2**n):
  rikai=[0]*m
  yen=0
  for j in range(n):
    if ((i>>j)&1):
      yen+=A[j][0]
      for w in range(1,m+1):
        rikai[w-1]+=A[j][w]
    if min(rikai)>=x:
      yeen.append(yen)
if yeen==[]:
  print(-1)
else:
  print(min(yeen))

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

cost = 1200001
for i in range(2**N):
    skill = [0]*M
    cost_ = 0
    for j in range(N):
        if i>>j & 1:
            cost_+=CA[j][0] 
            for k in range(M):
                skill[k] += CA[j][k+1]
    if all([l>=X for l in skill]):
        cost = min(cost_, cost)

if cost == 1200001:
    print(-1)
else:
    print(cost)

Solution (Python):

"""AtCoder Beginner Contest 167: C - Skill Up
https://atcoder.jp/contests/abc167/tasks/abc167_c
"""

N, M, X = 0, 0, 0
BOOKS = []


def calc_price(book_combinations, current_answer):
    price = 0
    
    understandings = [0] * M
    for i in range(len(book_combinations)):
        if book_combinations[i]:
            price += BOOKS[i][0]
            if current_answer < price:
                return -1  
            for j in range(len(BOOKS[i][1:])):
                understandings[j] += BOOKS[i][j + 1]
    for u in understandings:
        if u < X:  
            return -1
    return price


def main():
    global N, M, X, BOOKS
    N, M, X = list(map(int, input().split()))
    BOOKS = [list(map(int, input().split())) for i in range(N)]

    ans = float('inf')
    for i in range(1, 2 ** N):  
        price = calc_price([(i >> j) & 1 for j in range(N)], ans)
        if 0 < price and price < ans:
            ans = price
    if ans == float('inf'):
        ans = -1
    print(ans)


if __name__ == '__main__':
    main()