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 = [int(x) for x in input().split()]
CA = []
f = False
ans = 10**9
for _ in range(N):
    lst = [int(x) for x in input().split()]
    CA.append(lst)
for i in range(2**N):
    tmp = [0] * M
    c = 0
    for j in range(N):
        if ((i >> j) & 1):
            ca = CA[j]
            c += ca[0]
            for k in range(M):
                tmp[k] += ca[k+1]
    if min(tmp) >= X:
        f = True
        ans = min(ans, c)
print(ans if f else -1)

Solution (Python):
import itertools


def main():
    N, M, X = list(map(int, input().split(' ')))
    price = list()
    effect = list()
    for _ in range(N):
        data = list(map(int, input().split(' ')))
        price.append(data[0])
        effect.append(data[1:])
    INF = 10**10
    min_money = INF
    for pattern in itertools.product([0, 1], repeat=N):
        progress = [0 for _ in range(M)]
        for i in range(N):
            for j in range(M):
                progress[j] += pattern[i] * effect[i][j]
        ok = True
        for j in range(M):
            if progress[j] < X:
                ok = False
                break
        if ok:
            money = sum([p * m for p, m in zip(pattern, price)])
            if money < min_money:
                min_money = money
    if min_money == INF:
        print(-1)
    else:
        print(min_money)


if __name__ == '__main__':
    main()

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

ans = 10 ** 10
for bb in itertools.product([0, 1], repeat = n):
	comp = [0 for _ in range(m)]
	price = 0
	for i in range(n):
		if bb[i] == 1:
			for j in range(m):
				comp[j] += books[i][j + 1]
			price += books[i][0]
	if len([y for y in comp if y < x]) == 0:
		ans = min(ans, price)
if ans == 10 ** 10:
	print(-1)
else:
	print(ans)

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

inf = 10 ** 10
money = inf
for i in range(2**n):
    temp = 0
    r = [0] * m
    for j in range(n):
        if (i>>j)&1:
            temp += c[j]
            for k in range(m):
                r[k] += a[j][k]

    for j in r:
        if j >= x:continue
        break
    else:
        money = temp if temp < money else money

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

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

ans=10**9
for i in range(2**n):
  t_ans=0
  us=[0 for q in range(m)]
  for j in range(n):
    if (i>>j)&1:
      use=l[j]
      t_ans+=use[0]
      for w in range(m):
        us[w]+=use[w+1]
  check=1
  for z in us:
    if z<x:
      check=0
  if check==1:
    ans=min(ans,t_ans)

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

Solution (Python):
N, M, X = map(int, input().split())
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
ans = 100000000
for i in range(2**N):
    n = i
    al = [0] * M
    pr = 0
    for j in range(N):
        if n % 2 == 1:
            pr += A[j][0]
            for k in range(M):
                al[k] += A[j][k+1]
        n //= 2
    tes = 0
    for j in range(M):
        if al[j] < X:
            tes = 1

    if tes == 0:
        ans = min([ans, pr])

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

Solution (Python):
INF = 10 ** 12
def main():
    N, M, X = (int(_) for _ in input().split())
    C = [[int(_) for _ in input().split()] for _ in range(N)]
    out = INF
    for bit in range(1<<N):
        rikai = [0] * M
        cc = 0
        for i in range(N):
            if (bit >> i) & 1:
                cc += C[i][0]
                for j in range(1, M+1):
                    rikai[j-1] += C[i][j]
        if all([rikai[i] >= X for i in range(M)]):
            out = min(out, cc)
    print(out if out != INF else -1)
    return
if __name__ == '__main__':
    main()

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

ans = 10 ** 7
for i in range(2**n):
    money = 0
    a = [0] * m
    for j in range(n):
        if i >> j & 1:
            money += y[j][0]
            a = [a[k] + y[j][k+1] for k in range(m)]
    flag = True
    for j in a:
        if j < x:
            flag = False
    if flag:
        ans = min(ans, money)

if ans < 10 ** 7:
    print(ans)
else:
    print(-1)

Solution (Python):
import itertools

N,M,X = map(int,input().split())
COST = [0]*N
POWER = [0]*N
for i in range(N):
    AAA = list(map(int,input().split()))
    COST[i] = AAA[0]
    POWER[i] = AAA[1:]

INF = 10**10
ans = INF

for Q in itertools.product((0,1),repeat=N):
    c = 0
    p = [0]*M
    for k,v in enumerate(Q):
        if v == 0:
            continue
        c += COST[k]
        for kk,vv in enumerate(POWER[k]):
            p[kk] += vv
        b = True
        for i in range(M):
            if p[i] < X:
                b = False
                break
        if b:
            ans = min(ans,c)

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

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


ans = []
for i in range(2 ** n):
    num = [0] * m
    expense = 0
    for j in range(n):
        if i % 2 == 0:
            expense += c[j]
            for k in range(m):
                num[k] += a[j][k]
        i //= 2
    
    for j in num:
        if j < x:
            break
    else:
        ans.append(expense)

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

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

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

a = [sum(l) for l in zip(*A)]
if any(X > x for x in a):
    print(-1)
    exit(0)


ans = 1e18
for i in range(2 ** N):
    c = 0
    a = [0] * M
    price = 0
    for j in range(N):
        if (i >> j) & 1:
            price += C[j]
            for k in range(M):
                a[k] += A[j][k]
    if all(v >= X for v in a):
        ans = min(ans, price)

print(ans)

Solution (Python):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    n,m,x=L()
    understand=[0]*m
    book=[[0]*m for i in range(n)]
    price=[]*m
    for i in range(n):
        tmp=L()
        price.append(tmp[0])
        for j in range(m):
            book[i][j]=tmp[j+1]
    ans=1e+12
    for bit in range(1<<n):
        sum=0
        understand=[0]*m
        for i in range(n):
            if bit&(1<<i):
                sum+=price[i]
                for j in range(m):
                    understand[j]+=book[i][j]
        flag=True
        for i in range(m):
            if understand[i]<x:
                flag=False
        if flag:
            ans=min(ans,sum)
    if ans==1e+12:
        ans=-1
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
n,m,x=map(int,input().split())
ans=10**9
from itertools import combinations as co
l=[list(map(int,input().split())) for _ in range(n)]
for i in range(1,n+1):
  for ch in co(range(n),i):
    f=1
    t=[0]*m
    s=0
    for j in ch:
      s+=l[j][0]
      for k in range(1,m+1):
        t[k-1]+=l[j][k]
    for test in t:
      if test<x:
        f=0
        break
    if f:
      ans=min(ans,s)
if ans==10**9:
  ans=-1
print(ans)

Solution (Python):
import sys
import math
from collections import deque
import heapq
import itertools
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def check(l):
  for i in l:
    if i >= X:
      continue
    else:
      return False
  else:
    return True

N,M,X = IL()
ca = [IL() for i in range(N)]

ans = MAX_INT
for i in range(1 << N):
  x = 0
  rikaido = [0]*M
  for j in range(N):
    if (i >> j) & 1 == 1:
      x += ca[j][0]
      for k in range(1,M+1):
        rikaido[k-1] += ca[j][k]
  else:
    if check(rikaido):
      ans = min(ans, x)
if ans == MAX_INT:
  print(-1)
else:
  print(ans)

Solution (Python):
from itertools import product


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

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

ans = sum(c) + 10
for choose in product([0, 1], repeat=n):
	
	cost = 0
	good = True
	book = 0
	while good and book < m:
		sum_got = 0
		for buys in range(n):
			if choose[buys] == 1:
				sum_got += a[buys][book]
		
		if sum_got < x:
			good = False
			break
		book += 1

	if good:
		for buys in range(n):
			if choose[buys] == 1:
				cost += c[buys]
		
		if cost < ans:
			ans = cost
if ans != sum(c) + 10:
	print(ans)
else:
	print(-1)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m, x = na()
ca = nan(n)

ans = inf
for i in range(2 ** n):
    und = [0] * m
    money = 0
    for j in range(n):
        if (i >> j) & 1:
            c = ca[j][0]
            money += c
            for k in range(m):
                und[k] += ca[j][k + 1]
    flag = True
    for j in range(m):
        if und[j] < x:
            flag = False
    if flag:
        ans = min(ans, money)

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

Solution (Python):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import itertools
import math
n,m,x = ma()
cost = [0]*n
A = []
for i in range(n):
    co = list(ma())
    cost[i] = co[0]
    A.append(co[1:])
ans = 10**9
for i in range(2**n):
    tmp = 0
    cnt = [0]*m
    f = True
    for j in range(n):
        if i>>j &1:
            tmp+=cost[j]
            for k in range(m):
                cnt[k] +=A[j][k]
    for c in cnt:
        if c<x:
            f =False
    if f:ans = min(ans,tmp)
if ans==10**9:
    print(-1)
else:print(ans)

Solution (Python):
import numpy as np

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

loop_number = pow(2, n)

minimum_first = pow(10, 10)

minimum = 0
minimum += minimum_first

data = np.zeros((n, m+1))

for i in range(n):
    data[i] = np.asarray(input().split(), dtype=np.uint32)

for i in range(loop_number):
    a_sum = np.zeros(m)
    c_sum = 0
    for j in range(n):
        if np.bitwise_and(i, pow(2,j)):
            a_sum += data[j][1:]
            c_sum += data[j][0]

    if np.min(a_sum) >= x and c_sum < minimum:
        minimum = c_sum

if minimum == minimum_first:
    print(-1)
else:
    print(int(minimum))

Solution (Python):
import numpy as np

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

books = []

for i in range(n):
    books.append(list(map(int, input().split())))

books = np.array(books)

ok = 0
min_c = 100000000

for i in range(1 << n):
    ans = np.array([0 for j in range(m+1)])
    for k in range(n):
        if (i >> k & 1) == 1:
            ans += books[k]
    if ((ans[1:] - x) >= 0).all():
        ok = 1
        min_c = min(min_c, ans[0])

if not ok:
    print(-1)
else:
    print(min_c)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys

INF = 10 ** 17

def check(books, x, i, m, n):
    ab = [0 for i in range(m)]
    ret = 0
    for k in range(n):
        if i % 2 == 1:
            book = books[k]
            for tab, b in enumerate(book[1:]):
                ab[tab] += b
            ret += book[0]
        i //= 2
    
    for cab in ab:
        if cab < x:
            return INF

    return ret

def main():
    n, m, x = getList()
    books = [getList() for _ in range(n)]
    ans = INF
    for i in range(2**n):
        
        tmp = check(books, x, i, m, n)
        if ans > tmp:
            ans = tmp

    if ans == INF:
        print(-1)
    else:
        print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
N, M, X = map(int, input().split())
C = [0]*N
A = [[0 for _ in range(M)] for _ in range(N)]
for i in range(N):
    for j, x in enumerate(map(int, input().split())):
        if j == 0:
            C[i] = x
        else:
            A[i][j-1] = x

ans = 10**5*12+1
for bit_pattern in range(2<<N-1):
    i = 0
    tmp = [0]*M
    cost = 0

    while bit_pattern > 0:
        if bit_pattern & 1:
            for j in range(M):
                tmp[j] += A[i][j]
            cost += C[i]
        bit_pattern >>= 1
        i += 1

    for j in range(M):
        if tmp[j] < X:
            break
        if j == M-1:
            ans = min(ans, cost)
if ans == 10**5*12+1:
    ans = -1
print(ans)

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

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

ans=10**15
for i in range(len(PRD)):
    scores=[0 for i in range(M)]
    money=0
    
    for j in range(N):
        for k in range(M):
            scores[k]+=PRD[i][j]*A[j][k]
        money+=PRD[i][j]*C[j]
    
    if min(scores)>=X:
        ans=min(ans,money)

if ans==10**15:
    print(-1)
else:
    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):
    c[i],*aa = map(int,input().split())
    a[i]=aa

ans=10**50
for i in range(2**n):
    bi = bin(i)[2:].zfill(n)
    skill = [sum(a[k][j] for k in range(n) if bi[k]=="1") for j in range(m)]
    if all(s>=x for s in skill):
        cand = sum( c[i] for i in range(n) if bi[i]=="1")
        if cand<ans:
            ans=cand
if ans==10**50:
    print(-1)
else:
    print(ans)

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


INF = 1 << 31
ans = INF
for i in range(1 << N):
    curr_cost = 0
    understanding = [0] * M
    for j in range(N):
        if i >> j & 1:
            curr_cost += costs[j]
            for k in range(M):
                understanding[k] += A[j][k]
    if min(understanding) >= X:
        ans = min(ans, curr_cost)
if ans == INF:
    print(-1)
else:
    print(ans)

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

min_price = None
for t in range(2 ** N):
    price = 0
    values = [0] * M
    for i in range(N):
        if (1 << i) & t:
            price += C[i]
            for j in range(M):
                values[j] += A[i][j]
    if all(X <= v for v in values) and (min_price is None or price < min_price):
        min_price = price
print(min_price if min_price is not None else -1)

Solution (Python):















mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def dfs(pos):
    global n,m,x,a,ca,ans
    if pos==n:
        res = 0
        comp = [0] * m
        for i in range(n):
            if a[i]:
                res += ca[i][0]
                for j in range(1,m+1):
                    comp[j-1] += ca[i][j]
        for i in range(m):
            if comp[i]<x:
                return
        ans = min(ans,res)
        return
    a[pos] = 0
    dfs(pos+1)
    a[pos] = 1
    dfs(pos+1)

def main():
    global n,m,x,a,ca,ans
    n,m,x = readInt()
    ca = []
    for i in range(n):
        ca.append(readInt())
    ans = INF
    a = [0] * n
    dfs(0)
    if ans==INF:
        print(-1)
    else:
        print(ans)
    return

if __name__=='__main__':
    main()

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

L = [0]*n
C = [0]*n
for i in range(n):
    temp = list(map(int, input().split()))
    L[i] = temp[1:]
    C[i] = temp[0]

import itertools
ans = 10**18
for i in range(1, n+1):
    for p in itertools.combinations(range(n),i):
        
        temp = [0]*m
        cost = 0
        for j in range(len(p)):
            A = L[p[j]]
            cost += C[p[j]]
            for k in range(m):
                temp[k] += A[k]
        flag = True
        for l in range(m):
            if temp[l] < x:
                flag = False
        if flag:
            ans = min(ans, cost)
if ans == 10**18:
    print(-1)
else:
    print(ans)

Solution (Python):


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

price = []
a = []

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

ans = 10 ** 10
for num in range(2 ** n):
    rikaido = [0] * m
    cost = 0
    for i in range(n):
        
        buy = num & (1 << i) > 0
        if buy:
            for j in range(m):
                rikaido[j] += a[i][j]
            cost += price[i]
    
    target = True
    
    for j in range(m):
        if rikaido[j] < x:
            target = False
    
    if target:
        ans = min(cost, ans)

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

Solution (Python):

import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M, X = map(int, readline().split())
psum = 0
books = []
for i in range(N):
    c, *a = map(int, readline().split())
    assert len(a) == M
    books.append((c, a))
    psum += c


def solve():
    U = 1 << N
    minp = psum + 1
    for i in range(U):
        sel = i
        unds = [0] * M
        k = 0
        price = 0
        while (1 << k) < U:
            if (sel >> k) & 1:
                c, a = books[k]
                price += c
                for j in range(M):
                    unds[j] += a[j]
            k += 1
        if minp > price and all(x >= X for x in unds):
            minp = price

    if minp == psum + 1:
        return -1
    return minp


if __name__ == "__main__":
    print(solve())

Solution (Python):
n, m, x = map(int, input().split())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
flag = False
price = 10 ** 7
for i in range(2 ** n):
    num = bin(2 ** n + i)
    flag2 = True
    temp_price = 0
    a = [0] * m
    for j in range(n):
        if num[-j-1] == "1":
            temp = data[j][1:]
            temp2 = data[j][0]
            temp_price += temp2
            for k in range(m):
                a[k] += temp[k]
    for j in range(m):
        if a[j] < x:
            flag2 = False
            break
    if flag2 == True:
        flag = True
        price = min(price, temp_price)
if flag == True:
    print(price)
else:
    print(-1)

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

ans=10**7
for i in range(2**n):
    cost=0
    res=[0]*m
    for j in range(n):
        if ((i >> j) & 1):
            for k in range(m):
                res[k]+=c[j][k+1]
            cost+=c[j][0]
    for j in range(m):
        if res[j]<x:
            break
        if res[j]>=x and j==m-1:
            if cost<ans:
                ans=cost
if ans==10**7:
    print('-1')
else:
    print(ans)

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



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


ans = 10**9
for i in range(1 << n):
    abil = [0]*m
    val = 0
    for j in range(n):
        if ((i >> j) & 1):
            val += ca[j][0]
            for k in range(m):
                abil[k] += ca[j][k+1]
    if min(abil) >=  x:
        if val < ans:
            ans = val
if ans == 10**9:
    print(-1)
else:
    print(ans)

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

def main():
    N,M,X = map(int, readline().split())
    CA = [[int(i) for i in readline().split()] for _ in range(N)]
    
    ans = 10**15
    for i in range(2**N):
        m = [0] * M
        c = 0
        flag = True
        for j in range(N):
            if (i >> j) & 1:
                c += CA[j][0]
                for k in range(1,M+1):
                    m[k-1] += CA[j][k]
        for a in m:
            if a < X:
                flag = False
                break
        if flag:
            ans = min(ans, c)

    print(ans if ans < 10**15 else -1)


if __name__ == "__main__":
    main()

Solution (Python):
n, m, x = map(int,input().split())
books = []
for i in range(n):
    books.append(list(map(int,input().split())))
mi = 10**100
s = "0"+str(n)+"b"

for i in range(2**n):
    p = [0 for j in range(m)]
    money = 0
    k = str(format(i, s))
    for j in range(n):
        if k[j] == "1":
            money += books[j][0]
            for l in range(m):
                p[l] += books[j][l+1]
    if min(p) >= x and mi > money:
        mi = money

if mi == 10**100:
    print(-1)
else:
    print(mi)

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

ans = -1
for i in range(2 ** n):
    bi = list(bin(i)[2:].zfill(n))
    cost = 0
    understand = [0] * m
    for j, buy in enumerate(bi):
        if buy == "1":
            cost += c[j]
            for k in range(m):
                understand[k] += a[j][k]
    f = True
    for j in range(m):
        if understand[j] < x:
            f = False

    if f:
        if ans == -1:
            ans = cost
        else:
            ans = min(ans, cost)

print(ans)

Solution (Python):
def solve():
    N,M,X = map(int,input().split())
    C = []
    A = []
    for i in range(N):
        val = list(map(int,input().split()))
        C.append(val[0])
        A.append(val[1:])
    
    ans = float('inf')
    for i in range(1 << N):
        money = 0
        points = [0] * M
        for j in range(N):
            if (i >> j) & 1:
                money += C[j]
                for k in range(M):
                    points[k] += A[j][k]
        
        for j in range(M):
            if points[j] < X:
                break
        else:
            ans = min(ans,money)

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


                
if __name__ == '__main__':
    solve()

Solution (Python):
import sys
from pprint import pprint

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

books = []
for _ in range(N):
    tmp = list(map(int, sys.stdin.readline().split()))
    books.append(tmp)

ans = float("inf")
for i in range(1 << N):
    cost = 0
    scores = [0] * M
    for j in range(N):
        if i & (1 << j):
            cost += books[j][0]
            for k, score in enumerate(books[j][1:]):
                scores[k] += score
    for score in scores:
        if score < X:
            break
    else:
        ans = min(ans, cost)
            
print(-1 if ans == float("inf") else ans)

Solution (Python):

import sys
import itertools

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


def main():
    N, M, X = lmi()
    CA = llmi(N)

    def get_cost(set_of_bought):
        ans = 0
        for s in set_of_bought:
            ans += CA[s][0]
        return ans

    def check(set_of_bought):
        XX = [0] * M
        for s in set_of_bought:
            for i in range(M):
                XX[i] += CA[s][i + 1]
        if all(v >= X for v in XX):
            return True
        return False
    ans = INF
    for i in range(1 << N):
        cur = set()
        for n in range(N):
            if i>>n & 1:
                cur.add(n)
        

        if check(cur):
            ans = min(ans,get_cost(cur))
    if ans == INF:
        print(-1)
    else:
        print(ans)



if __name__ == '__main__':
    main()

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m,x = LI()
A = [LI() for _ in range(n)]

ans = inf
for i in range(1<<n):
    tmp = [0]*m
    preans = 0
    for j in range(n):
        if i >> j & 1:
            preans += A[j][0]
            for k,l in enumerate(A[j][1:]):
                tmp[k-1] += l
    for j in tmp:
        if j < x:
            break
    else:
        ans = min(ans, preans)
if ans == inf:
    print(-1)
else:
    print(ans)

Solution (Python):
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,2**n):
    a=[0]*m
    price=0
    for j in range(n):
        if i>>j&1:
            for k in range(m):
                a[k]+=ca[j][k+1]
            price+=ca[j][0]
    cnt=0
    for j in range(m):
        if a[j]>=x:
            cnt+=1
    if cnt==m:
        ans=min(ans,price)
if ans==10**9:
    print(-1)
else:
    print(ans)

Solution (Python):
N,M,X = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]
ans = 10**10
for i in range(2**N):
    cost = 0
    rikai = [0 for i in range(M)]
    for j in range(N):
        if i>>j&1:
            cost += A[j][0]
            for k in range(M):
                rikai[k] += A[j][k+1]
    b = True
    for k in range(M):
        if rikai[k] >= X:
            continue
        b = False
    if b:
        ans = min(ans,cost)
print(-1 if ans == 10**10 else ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N, M, X = map(int, input().split())
    books = [list(map(int, input().split())) for _ in range(N)]
    ans = float("inf")
    for i in range(2**N):
        cost = 0
        score = [0] * M
        for j in range(N):
            if ((i >> j) & 1):
                cost += books[j][0]
                for k in range(1, M+1):
                    score[k-1] += books[j][k]
        flag = True
        for j in range(M):
            if score[j] < X:
                flag = False
                break
        if flag:
            ans = min(ans, cost)
    if ans == float("inf"):
        print("-1")
    else:
        print(ans)
if __name__ == '__main__':
    main()

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

mi = 10**10
for i in range(2**n):
    skill = [0]*m
    price = 0
    for j in range(n):
        if (i>>j)&1:
            price += a[j][0]
            for k in range(m):
                skill[k] += a[j][k+1]
    for k in skill:
        if k<x:
            break
    else:
        mi = min(mi, price)
print(mi if mi<10**10 else -1)

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

res = 999999999999999999999999999
for i in range(2**n):
    pat = "{:020b}".format(i)
    pat = pat[::-1]
    
    cost = 0
    kekka = [0] * m
    for j in range(n):
        if pat[j] == "1":
            cost += dat[j][0]
            item = dat[j][1:]
            for k in range(m):
                kekka[k] += item[k]
    can = True
    
    
    for k in range(m):
        if kekka[k] < x:
            can= False
    if can:
        
        res = min(res, cost)

if res == 999999999999999999999999999:
    print(-1)
else:
    print(res)

Solution (Python):




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

result=10**9

for i in range(2**n):
    understand=[0]*m
    cost=0
    for j in range(n):
        if i>>j&1:
            temp=ca[j]
            cost+=temp[0]
            for index,item in enumerate(temp[1:]):
                understand[index]+=item
    flag=0
    for item in understand:
        if item<x:
            flag=1
    if flag==0:
        result=min(cost,result)
if result==10**9:
    print(-1)
else:
    print(result)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string,decimal
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,M,X = II()
CA=[list(map(int,list(input().split()))) for i in range(N)]
C_min = -1

for i in range(2 ** N):
  C_tmp = 0
  A_tmp = [0]*M
  for j in range(N):
    if ((i >> j) & 1):
      C_tmp += CA[j][0]
      for k in range(M):
        A_tmp[k] += CA[j][k+1]
  if all([l >= X for l in A_tmp]):
    if C_min == -1:
      C_min = C_tmp
    else:
      C_min = min(C_tmp,C_min)
print(C_min)