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())
C = []
for i in range(N):
    C.append(list(map(int,input().split())))


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

acost = 10**9

for i in range(len(bl)):
    tcost = 0
    tskill = [0]*M
    t = bl[i]
    for j in range(N):
        if t[j] == 1:
            tcost += C[j][0]
            for k in range(M):
                tskill[k] += C[j][k+1]
    if min(tskill) >= X:
        if acost > tcost:
            acost = tcost
            
if acost == 10**9:
    print(-1)
else:
    print(acost)

Solution (Python):
def make_smpl(m):
    if m == 0:
        return [[]]
    tmp = make_smpl(m - 1)
    result = []
    for l in tmp:
        result += [[0] + list(l), [1] + list(l)]
    return result


def calc(N, M, X, B):
    result = sum([b[0] for b in B])
    p = False
    for smpl in make_smpl(N):
        a = [0] * (M + 1)
        for i in range(N):
            if smpl[i] == 1:
                for j in range(M + 1):
                    a[j] += B[i][j]
        q = True
        for j in range(M):
            if a[j + 1] < X:
                q = False
                break
        if q:
            result = min(result, a[0])
            p = True
    return result if p else -1
    

(N, M, X) = tuple([int(s) for s in input().split()])
B = [[int(s) for s in input().split()] for _ in range(N)]
print(calc(N, M, X, B))

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

minsum=0
booklist=[]
for i in range(n):
    booklist.append(list(map(int,input().split())))
    minsum+=booklist[i][0]
minsum+=1
org=minsum
for i in range(2**n):
    masterlist=[0 for _ in range(m+1)]
    for j in range(n):
        if ((i>>j) & 1):
            for k in range(m+1):
                masterlist[k]=masterlist[k]+booklist[j][k]
    flag = True
    for l in range(1,m+1):
        if masterlist[l] < x:
            flag = False

    if flag:
        if masterlist[0] < minsum:
            minsum=masterlist[0]

if minsum == org:
    print(-1)
else:
    print(minsum)

Solution (Python):
import numpy as np

n, m, x = map(int, input().strip().split())
cs = []
aij = []
for _ in range(n):
    row = list(map(int, input().strip().split()))
    cs.append(row[0])
    aij.append(row[1:])


def check(bits, n, m, x):
    cost = 0
    skills = np.zeros(m, dtype=np.int)
    for i in range(n):
        bit = bits & (2 ** i)
        if bit:
            cost += cs[i]
            skills += aij[i]

    if np.all(skills >= x):
        return cost
    else:
        return False


min_cost = 1e30


for bits in range(2**n):
    result = check(bits, n, m, x)
    if not result:
        continue

    min_cost = min(min_cost, result)


if min_cost == 1e30:
    print(-1)
else:
    print(min_cost)

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M, X = lr()
    C = []
    A = []
    for i in range(N):
        CA = lr()
        C.append(CA[0])
        A.append(CA[1:])
    ans = float('inf')
    for i in range((1<<N)+1):
        rikai = [0]*M
        d = [0]*M
        tmp = 0
        for j in range(N):
            if (i>>j)&1:
                tmp += C[j]
                for k in range(M):
                    if d[k] == 1:
                        continue
                    rikai[k] += A[j][k]
                    if rikai[k] >= X:
                        d[k] = 1
        if d == [1]*M:
            ans = min(ans, tmp)
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)
resolve()

Solution (Python):
def f(i):
    global ans
    if i == n:
        t = []
        cost = 0
        for j in range(n):
            if s[j] == 1:
                t.append(j)
        for j in range(1, m + 1):
            c = 0
            for k in t:
                c += a[k][j]
            if not c >= x:
                return
        for j in t:
            cost += a[j][0]
        ans = min(ans, cost)
        return
    f(i + 1)
    s[i] = 1
    f(i + 1)
    s[i] = 0
 
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
s = [0] * n
ans = pow(10, 10)
f(0)
print(ans if not ans == pow(10, 10) else -1)

Solution (Python):






N,M,X = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(N)]
ans = 10**10

for i in range(2**N):
    A = []
    c = 0
    B = [0]*M
    for j in range(N):
        if ((i >> j) & 1):
            A.append(j)
    for k in A:
        for l in range(M):
            B[l] += C[k][l+1]
        c += C[k][0]
    if min(B) >= X:
        ans = min(ans,c)
if ans != 10**10:
    print(ans)
else:
    print(-1)

Solution (Python):
import numpy as np

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


c = np.array(c)
a = np.array(a)


def cost(buy):
    return np.dot(buy, c)


def learnable(buy):
    return np.min(np.dot(buy, a)) >= x


answer = False, 10 ** 8
for bit in range(2 ** n):
    buy = np.array([int(i) for i in bin(bit)[2:].zfill(n)])
    if learnable(buy):
        answer = True, min(answer[1], cost(buy))


if answer[0]:
    print(answer[1])
else:
    print(-1)

Solution (Python):
def main():
    from itertools import product
    n,m,x = map(int,input().split())
    A = []
    for i in range(n):
        a = list(map(int,input().split()))
        A.append(a)
    P = product([0,1], repeat=n)
    ans = float('inf')
    for p in P:
        a = [0 for i in range(m)]
        M = 0
        for i in range(len(p)):
            if p[i]==1:
                M += A[i][0]
                for j in range(1,len(A[i])):
                    a[j-1]+=A[i][j]
        flg = 0
        for i in range(len(a)):
            if a[i]<x:
                flg = 1
                break
        if M<ans and flg==0:
            ans = M
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()

Solution (Python):
def abc167_c():
    import numpy as np
    N, M, X = map(int, input().split())
    Cost = [0] * N
    Query = np.zeros((N, M), dtype=int)
    for i in range(N):
        row = list(map(int, input().split()))
        Cost[i] = row[0]
        Query[i] = row[1:]
    ans = 10**9

    from itertools import product
    for v in product(range(2), repeat=N):
        score = np.zeros(M, dtype=int)
        co = 0
        for i in range(N):
            if v[i] == 0: continue
            score += Query[i]
            co += Cost[i]
        if X <= np.min(score):
            ans = min(co, ans)
    if ans < 10**9: print(ans)
    else: print(-1)

abc167_c()

Solution (Python):
import numpy as np
if __name__ == "__main__":
    N, M, X = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(N)]
    ans = -1
    for i in range(2 ** N):
        rikai = np.zeros(M)
        cost = 0
        for j in range(N):
            if ((i>>j) & 1):
                cost += D[j][0]
                
                rikai = rikai + np.array(D[j])[1:]
        
        
        if np.all(X <= rikai):
            
            if ans == -1:
                ans = cost
            else:
                ans = min(ans, cost)
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    N, M, X = map(int, input().strip().split())
    C, A = [], []
    for i in range(N):
        line = list(map(int, input().strip().split()))
        C.append(line[0])
        A.append(line[1:])
    return N, M, X, C, A


def solve(N, M, X, C, A, INF = 10**8):
    stats = [0 for i in range(M)]
    
    def dfs(n):
        if all([s >= X for s in stats]):
            return 0
        if n >= N:
            return INF
        
        c1 = dfs(n+1)
        for i in range(M):
            stats[i] += A[n][i]
        c2 = dfs(n+1) + C[n]
        for i in range(M):
            stats[i] -= A[n][i]
        return min(c1, c2)

    c = dfs(0)
    return c if c < INF else -1


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
import sys
sys.setrecursionlimit(10000000)

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

ans = 10000000000000

hon = []


def dfs(cost, now, nextt):
    global N, M, X, ans, hon
    okcnt = 0
    for i in range(M):
        if now[i] >= X:
            okcnt += 1

    if okcnt == M:
        ans = min(cost, ans)

    if nextt >= N:
        return

    temp = now.copy()
    temp2 = now.copy()
    for j in range(M):
        temp[j] += hon[nextt][j + 1]

    dfs(cost + hon[nextt][0], temp, nextt + 1)
    dfs(cost, temp2, nextt + 1)


for i in range(N):
    c = list(map(int, input().split()))

    hon.append(c)

li = [0] * M

dfs(0, li, 0)

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

Solution (Python):
N,M,x = [int(x) for x in input().split()]
l = []
und = [0]*M
ans = 10**7
for i in range(N):
    uke = [int(x) for x in input().split()]
    l.append(uke)

for i in range(2**N):
    und = [0]*(M)
    money = 0
    for j in range(N):
        if ((i >> j)&1):
            money += l[j][0]
            for k in range(M):
                und[k] += l[j][k+1]
    if min(und) >= x:
        ans = min(ans,money)
if ans == 10**7:
    ans = -1
print(ans)

Solution (Python):
import sys
from io import StringIO
import unittest


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

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

    for i in range(2 ** n):
        cost = 0
        skills = [0] * m
        for j in range(n):
            if ((i >> j) & 1):
                cost += ca[j][0]
                for num, s in enumerate(ca[j][1:]):
                    skills[num] += s

        if all([sk >= x for sk in skills]):
            cost_list.append(cost)

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


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

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

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

    def test_入力例_3(self):
        input = """8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2"""
        output = """1067"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):

def ma():
    return map(int,input().split())
y="Yes"
t="No"
n,m,x=ma()
CA=[list(ma()) for _ in range(n)]

ans=10**9
for i in range(2**n):
    temp=0
    dp=[0]*m
    base=0
    
    while i>>base:
        if (i>>base)&1==1:
            
            temp+=CA[base][0]
            for j in range(m):
                dp[j]+=CA[base][j+1]
        base+=1
    
    for j in range(m):
        if dp[j]<x:
            break
    else:
        ans=min(ans,temp)
if ans==10**9:
    print(-1)
else:
    print(ans)

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

c, *aa = zip(*[tuple(map(int, input().split())) for _ in range(n)])
ans = float("inf")

for i in range(2 ** n):
    cnt = 0
    a = [0] * m
    items = [j for j in range(n) if (i >> j) & 1]

    for item in items:
        cnt += c[item]
        for k in range(m):
            a[k] += aa[k][item]
    
    if min(a) >= x: ans = min(cnt, ans)

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

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

for bit in range(1<<N):
    r = [0] * M
    v = 0
    for i in range(N):
        if (bit>>i) & 1 == 1:
            for j in range(M):
                r[j] += CA[i][j+1]
            v += CA[i][0]
    if all([X <= ri for ri in r]):
        vm = min(vm, v)
if vm == float('inf'):
    print(-1)
else:
    print(vm)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N, M, X = map(int, input().split())
    ans = 10 ** 9
    C_list = []
    A_list = []
    for _ in range(N):
        CA = list(map(int, input().split()))
        C_list.append(CA[0])
        A_list.append(CA[1:])
    for bit in range(2**N):
        cost = 0
        A = [0 for _ in range(M)]
        clear = True
        for i in range(N):
            if bit & 1<<i:
                cost += C_list[i]
                for j in range(M):
                    A[j] += A_list[i][j]
        for k in range(M):
            clear = clear and (A[k] >= X)
        if clear:
            ans = min(ans, cost)
    if ans == 10 ** 9:
        ans = -1
    print(ans)
if __name__ == "__main__":
    main()

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

p = []
books = []

for _ in range(N):
    tmp = list(map(int, input().split()))
    p.append(tmp[0])
    books.append(np.array(tmp[1:]))

saiyou = 0b00
ans = 10**7
for _ in range(2**N):
    mon = 0
    sat = np.zeros(M)
    for j, book in enumerate(books):
        if (saiyou >> j)&1 == 1:
            mon += p[j]
            sat += book
    if np.min(sat) >= X and ans > mon:
        ans = mon
    saiyou += 1

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

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

ans=13*pow(10,5)

for i in range(pow(2,N)):
    judge=str(bin(i))[2:].rjust(N,"0")
    
    cost=0
    li=[0]*M
    for j,s in enumerate(judge):
        if s=="1":
            cost+=CA[j][0]
            for k,a in enumerate(CA[j][1:]):
                li[k]+=a
    
    if min(li)>=X:
        ans=min(ans,cost)
if ans==13*pow(10,5):
    ans=-1
print(ans)

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

for _ in range(N):
    abc.append([int(v) for v in input().split()])


L = []
def dfs(index,c_L):
    if index == N:
        L.append(c_L)
        return
    dfs(index+1,c_L)
    n_L = c_L[:]
    n_L.append(abc[index])
    dfs(index+1,n_L)

dfs(0,[])

ans = float("inf")

for l in L:
    m = [0 for _ in range(M)]
    cost = 0
    for row in l:
        cost += row[0]
        for i,a in enumerate(row[1:]):
            m[i] += a

    flag = True
    for i in m:
        if i < X: flag = False
    if flag: ans = min(cost,ans)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

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

bit = []
for i in range(0, 2 ** N):
    pre_bit = []
    for k in range(N):
        pre_bit.append(i % 2)
        i = i // 2
    bit.append(pre_bit)

mi = 10 ** 7
for i in range(2 ** N):
    current = [0] * M
    okane = 0
    flag = 0
    for j in range(N):
        if bit[i][j] == 1:
            okane += CA[j][0]
            for k in range(M):
                current[k] += CA[j][k + 1]
    for i in range(M):
        if current[i] < X:
            flag = 1
    if flag == 0:
        if okane < mi:
            mi = okane

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

Solution (Python):
def main():
    n, m, x = tuple([int(e) for e in input().split()])
    matrix = []
    book_cost = []
    for i in range(n):
        arr = [int(e) for e in input().split()]
        book_cost.append(arr[0])
        matrix.append(arr[1:])

    best = float('inf')
    for i in range(1, (1 << n)):
        sm = [0] * m
        cost = 0
        for j in range(0, n):
            if (i >> j) & 1 > 0:
                for k in range(m):
                    sm[k] += matrix[j][k]
                cost += book_cost[j]
        if min(sm) >= x and cost < best:
            best = cost
    if best == float('inf'):
        print('-1')
    else:
        print(best)

if __name__ == '__main__':
    main()

Solution (Python):
N , M ,X = map(int,input().split())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    L.append(l)
ans = []
for i in range(2 ** N):
    rikai = [0 for _ in range(M)]
    cost = 0
    for b in range(N):
        if i  & (1 <<  b):
            for x in range(1,M + 1):
                rikai[x-1] += L[b][x] 
            cost += L[b][0]
    for x in rikai:
        if x < X: break
    else:
        ans.append(cost)
try:
    print(min(ans))
except:
    print(-1)

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


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


ans = 100000000

for i in range(2 ** n):
    kin = 0
    rikai = [0] * m
    for j in range(n):
        if ((i >> j) & 1):
            kin += ca[j][0]
            for k in range(m):
                rikai[k] += ca[j][k+1]
        if hantei(rikai):
            if kin < ans:
                ans = kin

if ans == 100000000:
    ans = -1

print(ans)

Solution (Python):
import copy

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


def make(x):
    global N

    bin_x=str(bin(x))[2:]
    rest=N-len(bin_x)
    bin_x=(bin_x[::-1]+'0'*(max(0,rest)))[::-1]

    return bin_x


cost=-1
for number in range(2**N):
    letter=make(number)
    develop=[0]*M
    temp=0
    for index in range(len(letter)):
        if letter[index]=='1':
            temp+=A[index][0]
            for j in range(1,M+1):
                develop[j-1]+=A[index][j]
    
    if X<=min(develop):
        if cost>=0:
            cost=min(cost,temp)
        else:
            cost=temp

print(cost)

Solution (Python):
def get_buy(i, N):
    ans = [0]*(N)
    for ind in range(N):
        if i % 2 == 1:
            ans[ind] = 1
        i //= 2
    return ans

N ,M, X = map(int, input().split())
CA = list()
for i in range(N):
    CA.append(list(map(int, input().split())))

ans = -1
for i in range(2**N):
    buy = get_buy(i, N)

    algorithm = [0]*M
    for j in range(N):
        if buy[j] == 1:
            for k in range(M):
                algorithm[k] += CA[j][k+1]
    
    ok = 1
    for j in range(M):
        if algorithm[j] < X:
            ok = 0

    
    
    
    
    
    
    

    if ok == 1:
        cost = 0
        for j in range(N):
            if buy[j] == 1:        
                cost += CA[j][0]
        
        if ans != -1:
            ans = min(ans, cost)
        else:
            ans = cost

print(ans)

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

for i in range(2**n):
    ans=[0]*m
    res=0
    for j in range(n):
        if not (i & (1<<j)):
            continue
        s=l[j]
        c=s[0]
        for k in range(m):
            ans[k]+=s[k+1]
        res+=c
    for i in range(m):
        if ans[i]<x:
            break
    else:
        money.append(res)
if money:
  print(min(money))
else:
  print(-1)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

def judge(li):
    algo = [0]*(m)
    cost = 0
    for i in range(len(li)):
        if li[i] == False:
            continue
        cost += C[i]
        for j in range(len(A[i])):
            algo[j] += A[i][j]
    for i in range(len(algo)):
        if algo[i]<x:
            return False
    return cost
n,m,x = map(int,input().split())
C = []
A = []
for i in range(n):
    d = list(map(int,input().split()))
    C.append(d[0])
    b = []
    for j in range(1,len(d)):
        b.append(d[j])
    A.append(b)
ans = 10000000000000
for i in range(2**n):
    li = [False]*n
    for j in range(n):
        if (i>>j)&1:
            li[n-j-1] = True
    a = judge(li)
    if a != False:
        ans = min(ans,a)
if ans == 10000000000000:
    print(-1)
else:
    print(ans)

Solution (Python):
from sys import stdin
from itertools import combinations
N, M, X = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for i in range(N):
    tmp = [int(x) for x in stdin.readline().rstrip().split()]
    data.append(tmp)

ans = 10**18
for i in range(1, N+1):
    for j in combinations(data, i):
        C = 0
        rikai = [0]*M
        for l in j:
            C += l[0]
            for ind, k in enumerate(l[1:]):
                rikai[ind] += k
        if len([i for i in rikai[:] if i >= X]) == M:
            ans = min(C, ans)
if ans == 10**18:
    ans = -1
print(ans)

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


pattern=[]
for i in range(2**n):
    tmp = [False]*n
    for j in range(n):
        if i >> j & 1:
            tmp[j] = True
    pattern.append(tmp)


kaisu=len(pattern)
ans=10**9
for i in range(kaisu):
    List=[0]*(m+1)
    for j in range(n):
        if (pattern[i][j]==True):
            for l in range(m+1):
                List[l]+=a[j][l]
    flag=0
   
    for k in range(1,m+1):
        if (List[k]<x):
            flag=1
            break
    if (flag==0):
        ans=min(ans,List[0])

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

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


n,m,x = mi()
C = [[] for _ in range(n)]

for i in range(n):
    c = li()
    for l in range(m+1):
        C[i].append(c[l])


anss = 10**9
for i in range(1<<n):
    alis = [0]*m
    ans = 0
    for k in range(n):
        if i>>k & 1:
            ans += C[k][0]
            for l in range(m):
                alis[l] += C[k][l+1]
    flag = 1
    for l in range(m):
        if alis[l] < x:
            flag = 0
    if flag:
        anss = min(anss,ans)

if anss == 10**9:
    print(-1)
    exit()
print(anss)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m,y=MI()
lis=[LI() for i in range(n)]
u=[]
point=[0 for i in range(m)]
for i in range(2**n):
    pay=0
    point=[0 for i in range(m)]
    for j in range(n):
        x=(i>>j) %2
        if x==1:
            for k in range(1,m+1):
                point[k-1]+=lis[j][k]
            pay+=lis[j][0]
    
    if min(point)>=y:
        u.append(pay)
    
if len(u)>0:
    print(min(u))
else:
    print("-1")

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

buys = []
for i in range(2**N):
    buy = []
    for j in range(N):
        if ((i>>j) & 1):
            buy.append(j)
    buys.append(buy)

ans = 10**9
flag = 1
for books in buys:
    cost = 0
    power = [0] * M
    for book in books:
        cost += C[book]
        for i in range(M):
            power[i] += A[book][i]

    if min(power) >= X:
        ans = min(ans, cost)
        flag = 0

print(-1 if flag else ans)

Solution (Python):

import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    N, M, X = IL(int)
    CA = ILL(int, N)
    ans = float('Inf')
    ok = False
    for bit in range(2 ** N):
        skill = [0] * M
        cost = 0
        for i in (b for b in range(N) if (0x01 << b) & bit):
            for j in range(M):
                skill[j] += CA[i][j + 1]
            cost += CA[i][0]
        if all(j >= X for j in skill):
            ok = True
            ans = min(ans, cost)

    print(ans if ok else -1)


solve()

Solution (Python):
n,m,x = map(int,input().split())
c=[0 for _ in range(n)]
a=[[] for _ in range(n)]
for i in range(n):
    c[i],*a[i] = map(int,input().split())
ans=sum(c)+1
alg=[0 for i in range(m)]
for i in range(int(2**n)):
    cnt=0
    al=alg[:]
    ii=i
    for j in range(n):
        r=i%2
        i=i//2
        if r ==1:
            cnt+=c[j]
            k=0
            for v in a[j]:
                al[k]+=v
                k+=1
    ok = True
    for y in al:
        if y<x:
            ok=False
            break
    if ok:
        ans=min(ans,cnt)
    
if ans==sum(c)+1:
    print(-1)
else:
    print(ans)

Solution (Python):

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

A=[]
C=[]


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

L=2**int(N)
ans=[]
for i in range(L):
    D=[0]*int(M)
    Z='{:012b}'.format(i)
    c=0
    for j in range(int(N)):
        if int(Z[11-j])==1:
            c+=C[j]
            for m in range(int(M)):
                D[m]+=A[j][m]           
    if min(D)>=int(X):
        ans.append(c)


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

print(ans)

Solution (Python):
c,m,x=map(int,input().split())
book=[list(map(int,input().split())) for i in range(c)]
ans=[False,float('inf')]
for i in range(1<<c):
  p=[0 for i in range(m)]
  num=0
  money=0
  while i>0:
    if i&1==1:
      money+=book[num][0]
      for j in range(1,m+1):
        p[j-1]+=book[num][j]
    num+=1
    i=i>>1
  if min(p)>=x and ans[1]>money:
    ans[0]=True
    ans[1]=money
if ans[0]:
  print(ans[1])
else:
  print(-1)

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

ans = 10**18
for i in range(1<<N):
    algo = np.array([0]*M)
    cost = 0
    for j in range(N):
        if (i>>j)&1:
            c, *al = books[j]
            al = np.array(al)
            algo += al
            cost += c
    if np.all(algo>=X):
        ans = min(ans, cost)

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

Solution (Python):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m,x=n1()
ca=n3(n)
ca

import itertools
book=list(itertools.product([0,1], repeat=n))
price=[]
for line in book:
    p=0
    for i in range(n):
        if line[i]==1:
            p+=ca[i][0]
            
    price.append(p)
A=[[book[i],price[i]] for i in range(len(book))]
A.sort(key=lambda x:x[1])

for line in A:
    t=line[0]
    s=[0]*m
    for i in range(n):
        if t[i]==1:
            s=[s[j]+ca[i][j+1] for j in range(m)]
    if len([i for i in s if i>=x])==m:
        print(line[1])
        break
else:
    print(-1)

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

ans = float('inf')
for i in range(2 ** N):
    s = []
    for j in range(N):
        if (i >> j) & 1:
            s.append(j)

    
    cost = 0
    score = [0] * M
    for t in s:
        cost += C[t]
        for k, a in enumerate(A[t]):
            score[k] += a
    
    flag = True
    for sc in score:
        if sc < X:
            flag = False
            break
    if flag:
        ans = min(ans, cost)


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

Solution (Python):
N,M,X=map(int,input().split())
C = [0] * N
A = [ [0 for i in range(M)] for i in range(N) ]
for i in range(N):
  CA = list(map(int,input().split()))
  C[i] = CA[0]
  A[i] = CA[1:]
INF = 100000000
ans = INF
for i in range( 1 << N ):
  cost = 0
  r = [0] * M
  for j in range(N):
    if (i & (1 << j) != 0):
      cost += C[j]
      for k in range(M):
        r[k] += A[j][k]
  ok = 1
  for k in range(M):
    if r[k] < X:
      ok = 0
  if ok == 1:
    ans = min(ans, cost)


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

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

from itertools import combinations

minprice = 10**13
for i in range(1, n + 1):
    l = list(combinations(range(n), i))
    for singleper in l:
        res = [0] * m
        price = 0
        for single in singleper:
            for j in range(m):
                res[j] += a[single][j]
            price += c[single]
        ok = True
        for j in range(m):
            if res[j] < x:
                ok = False
                break
        if ok:
            minprice = min(minprice, price)

if minprice == 10**13:
    print(-1)
else:
    print(minprice)

Solution (Python):

import numpy as np

N, M, X = map(int, input().split())
d = []
money = []

for _ in range(N):
    tmp = list(map(int, input().split()))
    money.append(tmp[0])
    d.append(np.array(tmp[1:]))

ans = 10 ** 9
for i in range(1, 2 ** N + 1):
    bought = []
    okane = 0
    for k in range(N):
        if i >> k & 1 == 1:
            bought.append(d[k])
            okane += money[k]
    total = np.zeros(M)
    for j in bought:
        total += j
    if sum(total >= X) == M:
        ans = min(ans, okane)

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