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

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

ans_list_ = []

origin_list = data
for i, _ in enumerate(origin_list, 1):     
  for j in itertools.combinations(origin_list, r=i):  
    

    
    each_point_list_ = [0] * m
    for j_ in j:
      for m_ in range(m):
        each_point_list_[m_] += j_[m_+1]

    
    flag_ = True
    for epl in each_point_list_:
      if epl < x:
        flag_ = False
    
    if flag_:
      
      price_ = 0
      for j_ in j:
        price_ += j_[0]
      
      ans_list_.append( price_ )

    

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

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


ans = [10**9]
index = 0
score = [0]*M
coin = 0
import copy

def rec(index,coin,score):
    
    if index > N-1:
        f = True
        for i in range(M):
            if score[i] < X:
                f = False
        if f:
            
            
            ans[0] = min(ans[0],coin)

        return 1
    
    
    
    score1 = copy.deepcopy(score)
    rec(index+1,coin,score1)

    for i in range(M):
        score1[i] += C[index][i+1]
    
    
    rec(index+1,coin+C[index][0],score1)
    
    return 1


rec(index,coin,score)

if ans[0]==10**9:
    ans[0] = -1
print(ans[0])

Solution (Python):
import itertools

N, M, X = map(int, input().split())
C = []
for i in range(N):
    C.append(list(map(int, input().split())))
choice = list(itertools.product([False, True], repeat = N))

best = False
for i in choice:
    cost = 0
    now = [0 for j in range(M)]
    flag = True
    for j in range(N):
        if i[j]:
            cost += C[j][0]
            now = [now[k] + C[j][k + 1] for k in range(M)]
    for j in now:
        if j < X:
            flag = False

    if flag:
        if best == False:
            best = cost
        elif best > cost:
            best = cost
if best == False:
    print(-1)
else:
    print(best)

Solution (Python):
from itertools import combinations
I=lambda:list(map(int,input().split()))
n,m,x=I()
rec=[]
for i in range(n):
  rec.append(I())
best=10**9
for i in range(1,n+1):
  l=list(combinations(rec,i))
  
  for j in range(len(l)):
    loc_best=0
    algos=[0 for _ in range(m+1)]
    for k in range(len(l[j])):
      loc_best+=l[j][k][0]
      for p in range(1,m+1):
        algos[p]+=l[j][k][p]
    
    st=False
    for p in range(1,m+1):
      if(algos[p]<x):
        st=True
        break
    if(st==False):
      best=min(loc_best,best)
if(best==10**9):
  print(-1)
else:
  print(best)

Solution (Python):
import itertools as itt

n,m,x = map(int, input().split())
lsts = []
cbs = []
minp = -1

for i in range(n):
  lsts.append(input().split())
  for j in range(m+1):
    lsts[i][j] = int(lsts[i][j])


for i in range(1,n+1):
  cbs += list(itt.combinations(lsts,i))


for i in range(len(cbs)):
  p = 0
  algs = [0]*m
  flg = True
  for j in range(len(cbs[i])):
    p += cbs[i][j][0]
    for k in range(m):
      algs[k] += cbs[i][j][k+1]
  for alg in algs:
    if alg < x:
      flg = False
  if flg and (minp == -1 or p < minp):
    minp = p


print(minp)

Solution (Python):


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

mylist = []

for n in range(N):
    costlist = list(map(int, input().split()))
    mylist += [costlist]


mymin =  float('INF')
for i in range(2 ** N):             
    myflag = [0 for i in range(N)]  
    for j in range(N):
        if ((i >> j) & 1):          
            myflag[n - 1 - j] = 1

    mycost = 0
    myab = [0 for m in range(M)]
    
    for n in range(N):
        if myflag[n] == 1:
            mycost += mylist[n][0]
            for m in range(M):
                myab[m] += mylist[n][m+1]
    if min(myab) >= X:
        if mycost < mymin:
            mymin = mycost
            
if mymin == float('INf'):
    print(-1)
else:
    print(mymin)

Solution (Python):
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


    

n,m,x=mi()

a=[[0 for i in range(m)]for j in range(n)]
p=[0]*n
for i in range(n):
    a1=li()
    p[i]=a1[0]
    a[i]=a1[1:]

ans=1000000007
for i in range(1,pow(2,n)):
    s=bin(i)[2:]
    s='0'*(n-len(s))+s
    s1=0
    x1=[0]*m
    for j in range(n):
        if s[j]=='1':
            for k in range(m):
                x1[k]+=a[j][k]
            s1+=p[j] 
    f1=1
    for j in range(m):
        if(x1[j]<x):
            f1=0
        
    if(f1):
        ans=min(ans,s1)
if(ans==1000000007):
    ans=-1
print(ans)

Solution (Python):
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def int_input():
    return int(input())


def print_ans(string):
    print(string)
    exit()

def yes():
    print("Yes")
    exit()

def no():
    print("No")
    exit()

import numpy as np

N,M,X=input_int_list()
np_list=[np.array(input_int_list(),dtype=int) for i in range(N)]
kakaku_list=[]
for i in range(2**N):
    the=np.zeros((1,M),dtype=int)
    kakaku=0
    for j in range(N):
        if format(i,"b").zfill(N)[j]=="1":
            the=the+np_list[j][1:]
            kakaku=kakaku+np_list[j][0]
    if (the>=X).all():
        kakaku_list.append(kakaku)
if len(kakaku_list)!=0:
    print_ans(min(kakaku_list))
else:
    print_ans(-1)

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

ans = 10**15
flag = False
for i in range(2**N):
    r = np.array([0]*(M+1))

    for j in range(N):
        if (i>>j)&1:
            for k in range(M+1):
                r[k] += A[j][k]
    
    if np.all(r[1:]>=X):
        if ans > r[0]:
            ans = r[0]
        flag = True
    else:
        flag = False
        
if flag:
    print(ans)
else:
    print("-1")

Solution (Python):
from itertools import combinations
import numpy as np
N,M,X = map(int,input().split())
setto = list(range(N))
ans = 10**18
sankosyo = [list(map(int,input().split())) for i in range(N)]
subsets = []
for i in range(N+1):
    for c in combinations(setto,i):
        subsets.append(c)
for subset in subsets:
    cost = 0
    rikaido = np.array([0]*M)
    if subset == set():
        continue
    for i in subset:
        cost += sankosyo[i][0]
        for idx,A in enumerate(sankosyo[i][1:]):
            rikaido[idx] += A
    if np.count_nonzero(rikaido < X) == 0:
        ans = min(ans,cost)
if ans == 10**18:
    print(-1)
else:
    print(ans)

Solution (Python):
N, M, X = [int(x) for x in input().split()]
C = [None] * N
A = [None] * N
for i in range(N):
    K = [int(x) for x in input().split()]
    C[i] = K[0]
    A[i] = K[1:]
INF = float('inf')

ans = INF
for n in range(1, 2 ** N):
    select = bin(n)[2:].zfill(N)
    cost = 0
    S = [0] * M 
    for i in range(N): 
        if int(select[i]) == 0: continue
        cost += C[i]
        for j in range(M): 
            S[j] += A[i][j]

    if cost >= ans: continue
    for j in range(M):
        if S[j] < X: break
    else:
        ans = cost

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

Solution (Python):
N,M,X=map(int,input().split())
C=[]
A=[]
for _ in range(N):
    ci,*ai = map(int,input().split())
    C.append(ci)
    A.append(ai)

sum_x = [0 for i in range(M)]
for i in range(N):
    ai = A[i]
    for j,aij in enumerate(ai):
        sum_x[j] += aij
min_x = min(sum_x)
if min_x<X:
    print('-1')
    exit()


import math
max_bit = 2**(N)
min_expense = math.inf
for i in range(2**(N)):
    binary = bin(max_bit+i)[1+2:]
    sum_x = [0 for _ in range(M)]
    expense = 0
    for j,b in enumerate(binary):
        if b=='1':
            expense += C[j]
            for k,ajk in enumerate(A[j]):
                sum_x[k] += ajk
    min_x = min(sum_x)
    if min_x<X:
        continue
    min_expense = min(expense,min_expense)

print(min_expense)

Solution (Python):




def input_int():
    return int(input())



def int1(x):
    return int(x) - 1



def input_to_int_map():
    return map(int, input().split())



def input_to_int_tuple():
    return tuple(map(int, input().split()))



def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, m, x = input_to_int_map()
    ca = [input_to_int_tuple() for i in range(n)]

    import itertools
    ret = 10 ** 10
    for temp in itertools.product([0, 1], repeat=n):
        money = 0
        understands = [0] * m
        for i, val in enumerate(temp):
            if val == 1:
                t_ca = ca[i]
                money += t_ca[0]
                a = t_ca[1:]
                for j, under in enumerate(a):
                    understands[j] += under
        if len(list(filter(lambda t : t >= x, understands))) == m:
            ret = min(ret, money)

    if ret == 10 ** 10:
        ret = -1

    return ret


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

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

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

arr = np.array(l)

minimum = 10 ** 5 * 13
for boo in itertools.product([True, False], repeat=n):
    if arr[np.array(list(boo))].sum(axis=0)[1:m+1].min() >= x:
        temp = arr[np.array(list(boo))].sum(axis=0)[0]
        if temp < minimum:
            minimum = temp

if arr.sum(axis=0)[1:m+1].min() < x:
    print(-1)
else:
    print(minimum)

Solution (Python):
import numpy as np

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

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

ans = 1000000000
found = False

for i in range(2 ** N):
    tmp = [0] * (M + 1)
    books = np.array(tmp)
    for j in range(N): 
        if ((i >> j) & 1):
            books = books + np.array(C[j])

    skill_good = True
    for k in range(1,M+1):
        if books[k] < X:
            skill_good = False

    if books[0] < ans and skill_good:
        ans = books[0]
        found = True

if found:
    print(ans)
else:
    print(-1)

Solution (Python):
import itertools
def main():
    N,M,X = map(int, input().split())
    C = [0 for i in range(N)]
    A = [[0]*M for i in range(N)]
    for i in range(N):
        tmp = list(map(int, input().split()))
        C[i] = tmp[0]
        A[i] = tmp[1:(M+1)]

    texts_no = [i for i in range(N)]
    price_min = 0
    for i in range(1,N+1):
        
        cmb = list(itertools.combinations(texts_no,i))
        for cmbset in cmb:
            
            understand = [0 for _ in range(M)]
            price_tmp = 0
            for text in cmbset:
                understand = [understand[j]+A[text][j] for j in range(M)]
                price_tmp += C[text]
            
            joken = [True if n>=X else False for n in understand]
            if False not in joken:
                if price_min==0: price_min = price_tmp
                else: price_min = min(price_min, price_tmp)

    if price_min!=0: print(price_min)
    else: print(-1)


main()

Solution (Python):
import sys
import itertools


import numpy as np


N,M,X = map(int, sys.stdin.readline().strip().split())
C = []
for _ in range(0, N):
    C.append(list(map(int, sys.stdin.readline().strip().split())))











C.sort(key=lambda x:x[0])

ans = None
for i in range(1, N+1):
    for j in itertools.combinations(C, i):
        l = [k[1:] for k in j]
        
        if len(l) > 1:
            ll = np.sum(l, axis=0)
            
            flag = all((m >= X) for m in ll)
        else:
            flag = all((m >= X) for m in l[0])
        if flag:
            n = np.sum(j, axis=0)[0]
            if ans == None or  ans > n:
                ans = n

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

Solution (Python):
n, m, x = list(map(int, input().split()))
z = [list(map(int, input().split())) for _ in range(n)]
nux = 10**13
for i in range(2**n):
    alu = [-x]*m
    buy = []
    for j in range(n):
        if (i >> j) & 1:
            buy.append(j)
    num = 0
    if i == 30:
        s = 1
    for k in buy:
        num += z[k][0]
        for ss in range(m):
            alu[ss] += z[k][ss+1]
    if len([i for i in alu if i < 0]) == 0:
        nux = min(num, nux)
if nux == 10**13:
    print(-1)
else:
    print(nux)

Solution (Python):
import itertools
N,M,X = map(int,input().split())
book =[]
for x in range(N):
    A_list =  list(map(int, input().split()))
    book.append(A_list)
conbination =[]
for i, _ in enumerate(book, 1):     
    for j in itertools.combinations(book, r=i):  
        conbination.append(j)
minn =100000000
for x in conbination:
    A = [0]*M
    m = 0
    for y in x:
        for z in range(len(y)):
            if z ==0:
                m +=y[z]
            else:
                A[z-1] +=y[z]
    if minn >m and X<=min(A):
        minn =m
        
if minn != 100000000:
    print(minn)
else:
    print(-1)

Solution (Python):
import itertools
import numpy as np

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

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

min=10000000000000000000000000
for i in range(1,n+1):
    a=list(itertools.combinations(list(range(n)), i))
    for j in a:
        cost=0
        l2=np.zeros(m)
        for k in j:
            b=np.array(l[k][1:])
            l2+=b
            cost+=l[k][0]
            if np.all(l2>=x) and cost<min:
                min=cost

if min==10000000000000000000000000:
    print(-1)
else:
    print(min)

Solution (Python):
import itertools as it

n,m,x=map(int, input().split())
l=[]
check=[0]*(m)
ans=0
for i in range(n):
    a=list(map(int, input().split()))
    ans+=a[0]
    for j in range(m):
        check[j]+=a[j+1]
    l.append(a)

if min(check)<x:
    print('-1')
    exit()


for i in range(1,n+1):
    for p in it.combinations(range(n), i):
        
        mon=0
        che=[0]*m
        for j in range(len(p)):
            mon+=l[p[j]][0]
            for k in range(m):
                che[k]+=l[p[j]][k+1]
        
        if min(che)>=x:
            ans=min(ans,mon)

print(ans)

Solution (Python):
import itertools

p = list(map(int,input().split()))
N = p[0]
M = p[1]
X = p[2]

l = [[int(i) for i in input().split()] for j in range(N)]

hoge = []
kouho = list(range(1,N+1))
for i in itertools.combinations_with_replacement(kouho, N):
    hoge.append(list(set(i)))

hoge = list(map(list, set(map(tuple, hoge))))
last_val = float('inf')
flag = False

for ls in hoge:
    ls = list(set(ls))
    ans = [0] * M
    val = 0
    for a in ls:
        for ix,i in enumerate(l[a-1][1:]):
            ans[ix] += i
        val += l[a-1][0]
    b = [i for i in ans if i >= X]
    if len(b) == len(ans):
        last_val = min(last_val, val)
        flag = True

if flag:
    print(last_val)
else:
    print(-1)

Solution (Python):
import itertools

n, m, x = map(int, input().split())
cost = 10**9
a = [list(map(int, input().split()))]

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

for i in range(1, n + 1): 
    for j in itertools.combinations(range(n), i): 
        l = [0]*(m + 1)
        for k in j: 
            for o in range(m + 1): 
                l[o] += a[k][o]
        cnt = 0
        for p in range(1, m + 1):
            if l[p] < x:
                break
            else:
                cnt += 1
        if cnt == m:
            cost = min(cost, l[0])


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

Solution (Python):
n, m, x = list(map(int, input().split()))
a = []
c = []
for _ in range(n):
    list_ = list(map(int, input().split()))
    c.append(list_[0])
    list_.pop(0)
    a.append(list_)
res = -1
bit = []
for i in range(2 ** n):
    tmp = [False] * n
    for j in range(n):
        if i >> j & 1:
            tmp[j] = True
    bit.append(tmp)
bit.pop(0)
cost = 10 ** 10
f = False
for i in range(2 ** n - 1):
    tmp_cost = 0
    tmp_f = True
    list_ = [0] * m
    for j in range(n):
        if bit[i][j]:
            tmp_cost += c[j]
            for k in range(m):
                list_[k] += a[j][k]
    for k in range(m):
        if list_[k] >= x:
            pass
        else:
            tmp_f = False
    if tmp_f:
        cost = min(tmp_cost, cost)
        f = True
if f:
    res = cost
print(res)

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

import numpy as np


N, M, X = map(int, readline().split())
C = []
A = []
ans = []

for _ in range(N):
    I = list(map(int, readline().split()))
    c = I.pop(0)
    C.append(c)
    a = np.array(I)
    A.append(a)

for b in range(2**12):
    c = 0
    U = np.zeros((M,))
    for i in range(N):
        f = b >> i & 1
        if f:
            c += C[i]
            U = U + A[i]
    if np.all(U >= X):
        ans.append(c)

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

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

c=float('inf')
p=0
for i in range(2**(n+1)):
    al=[0]*m
    cost=0
    for j in range(n):
        if (i>>j)&1:
            for k in range(1,m+1):
                al[k-1]+=lis[j][k]
            cost+=lis[j][0]
    if min(al)>=x:
        c=min(c,cost)
        p=1
print(c) if p==1 else print(-1)

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

C = [0] * N
A = [[] for _ in range(N)]

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

ans = float("inf")
for i in range(1<<N):
    S = []
    for j in range(N):
        if i & (1<<j):
            S.append(j)
    
    W = [0] * M
    for s in S:
        for j in range(M):
            W[j] += A[s][j]
    
    flag = True
    for j in range(M):
        if W[j] < X:
            flag = False
            break

    if flag:
        res = 0
        for s in S:
            res += C[s]
        ans = min(ans, res)

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

Solution (Python):
import numpy as np
n,m,x = map(int,input().split())
c_list = []
a_list = []
flag = False
ans = 10**9
for i in range(n):
    tmp = list(map(int,input().split()))
    c_list.append(tmp[0])
    a_list.append(tmp[1:])
    
a_list = np.array(a_list)

for i in range(2**n):
    tmp_a = np.array([0]*m)
    tmp_c = 0
    for j in range(n):
        if ((i >> j) & 1):
            tmp_a += a_list[j]
            tmp_c += c_list[j]
    
    if min(tmp_a) >= x:
        flag = True
        if tmp_c < ans:
            ans = tmp_c
            
if flag:
    print(ans)
    
else:
    print(-1)

Solution (Python):
import numpy as np

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


sets = []

for i in range(n):
  sets.append(list(map(lambda x: int(x), input().split(' '))))  
sets = np.array(sets)


mincost = 10000000
maxnum = int(''.join(["1" for i in range(n)]), 2)

if not np.all((np.sum(sets[:, 1:], axis=0) >= x)):
  print(-1)
else:
  for i in range(0, maxnum+1):
    status = np.array(list(format(i, '0{}b'.format(n)))) == '1'
    used_data = sets[status]
    cost = np.sum(used_data[:, 0])
	
    if cost > mincost:
      continue
    if np.all((np.sum(used_data[:, 1:], axis=0) >= x)):
      if cost < mincost:
        mincost = cost
        next
    
  print(mincost)

Solution (Python):
import numpy
N, M, X = map(int, input().split())
status = []
for n in range(N):
    li = list(map(int, input().split()))
    status.append(li)
minimum = 10**12
def dp(depth, money, oklist):
    global minimum
    ok = oklist
    if depth == N:
        tf = True
        for m in range(M):
            if ok[m] < X:
                tf = False
        if tf:
            if money < minimum:
                minimum = money
        ok = [0]*M
        return
    dp(depth+1, money, ok)


    dp(depth+1, money+status[depth][0],ok+numpy.array([status[depth][m+1] for m in range(M)]))
oklist = numpy.array([0]*M)
dp(0, 0, oklist)
if minimum == 10**12:
  print(-1)
else:
  print(minimum)

Solution (Python):
import itertools

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

ans = []
for num_book in range(1, N + 1):
    for i in itertools.combinations(list_N, num_book):
        
        temp = 0
        for j in range(1, M + 1):
            sum_line = sum([s[i[k]][j] for k in range(num_book)])
            if sum_line < X:
                break
            temp += 1
            if temp == M:
                score=sum([s[i[k]][0] for k in range(num_book)])
                
                ans.append(score)
    
    
if len(ans)==0:
    print(-1)
else:
    
    print(min(ans))

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

def main():
    n,m,x=map(int,input().split())
    C=[]
    A=[]
    for _ in range(n):
        c,*a=map(int,input().split())
        C.append(c)
        A.append(a)
    ans=float('inf')
    for i in range(1<<n):
        S=[0]*m
        tmp=0
        for j in range(n):
            if (i>>j)&1==0:
                continue
            tmp+=C[j]
            B=A[j]
            for k,b in enumerate(B):
                S[k]+=b
        for s in S:
            if s<x:
                break
        else:
            ans=min(ans,tmp)
    print(-1 if ans==float('inf') else ans)
    
if __name__=='__main__':
    main()

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

import numpy as np

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

vals = np.array(vals)

import itertools

prod = []
for i in range(1, N+1):
    v = list(itertools.combinations(range(N), i))
    prod.extend(v)
    
money = 1e10

for p in prod:
    ans = np.zeros(M+1)
    
    for p_ in p:
        ans += vals[p_]
    
    flag = True
    for j in range(M):
        if ans[1+j] < X:
            flag = False
    if flag:
        if money > ans[0]:
            money = ans[0]
 
if money >= 1e10:
    print(-1)
else:
    print(int(money))

Solution (Python):
import itertools

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

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

cost = []

for i in range(1, n + 1):
    for k in itertools.combinations(range(n), i):
        c = 0
        a_list = [0] * m
        for l in k:
            c += a[l][0]
            for p in range(1, m + 1):
                a_list[p - 1] += a[l][p]
        
        if min(a_list) < x:
            continue
        else:
            cost.append(c)

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

Solution (Python):
import sys
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,m,x = inputs()
c = [inputs() for _ in range(N)]
cnt =[0]*(N)
ans = 10**8
for bit in range(1,1<<N):
    ans1 = 0
    cnt =[0]*(N)
    skill=[0]*m
    for j in range(N):
        if bit&1<<j:
            for i in range(1,m+1):
                skill[i-1]+=c[j][i]
            ans1+=c[j][0]
    snt =0
    for i in range(m):
        if(skill[i]>=x):
            snt+=1
        if(snt==m):
            ans=min(ans,ans1)
if ans==10**8:
    print(-1)
    exit()
print(ans)

Solution (Python):

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



flag = True
for bits in itertools.product([1, 0], repeat=n):
    skill = [0] * m 
    cost = 0
    if all(bits):
        for r in refs:
            skill = [x + y for (x, y) in zip(skill, r[1:])]
            cost += r[0]
        if any([i < x for i in skill]): 
            flag = False
            break
        else:
            ans = cost 

    else:
        for i, b in enumerate(bits):
            if b == 1:
                skill = [x + y for (x, y) in zip(skill, refs[i][1:])]
                cost += refs[i][0]
        if all([i >= x for i in skill]):
            ans = min(ans, cost)

if flag:
    print(ans)
else:
    print(-1)

Solution (Python):
import sys
import copy
sys.setrecursionlimit(2**20)
N, M, X = map(int, input().split())

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

ans = float("inf")
def dfs(T, cost, i):
    global ans
    TT = copy.deepcopy(T)
    if i == N:
        flag = True
        for t in TT:
            if not t >= X:
                flag = False
        if not flag:
            return
        
        ans = min(ans, cost)
        return
    dfs(TT, cost, i+1)
    for j in range(M):
        TT[j] += A[i][j]
    dfs(TT, cost+C[i], i+1)

T = [0]*M
dfs(T, 0, 0)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Solution (Python):
import numpy as np
N,M,X= map(int, input().split())
q = [list(map(int, input().split())) for _ in range(N)]
q = np.array(q)
ans = []
for j in range(2**N):
    list = []
    cost = 0
    for k in range(N):
        if (j >> k)&1:
            list.append(1)
        else:
            list.append(0)
    list = np.array(list)
    for l in range(N):
        cost +=  q[l] * list[l]
    if min(cost[1:]) >= X:
        ans.append(cost[0])
if len(ans) == 0:
    ans.append(-1)
print(min(ans))

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

mn = -1
for bit in range(1 << n):
    tmp = [0] * m
    t = 0
    for i in range(n):
        if (bit & (1<<i)):
            t += c[i]
            for j in range(m):
                tmp[j] += a[i][j]
    if t != 0 and (mn > t or mn == -1) and len([i for i in tmp if i >= x]) == len(tmp):
        mn = t

print(mn)

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m,x=LI()
  l=[LI() for _ in range(n)]

  ans=inf
  for i in range(1<<n):
    ans_l=[0]*m
    sm=0
    for j in range(n):
      if i&(1<<j):
        for _i,y in enumerate(l[j]):
          if _i>0:
            ans_l[_i-1]+=y
        sm+=l[j][0]
    
    f=True
    for _x in ans_l:
      if _x<x:
        f=False
    if f:
      ans=min(ans,sm)

  if ans==inf:
    return -1

  return ans


print(main())

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

for i in range(n) :
    ca = list(map(int,input().split()));
    price[i] = ca[0];
    for j in range(m) :
        rikai[i][j] = ca[j+1];

ans = sum(price);
able = 0;
for i in range(2**n) :
    allrikai = [0]*m;
    nowprice = 0;
    for j in range(n) :
        if (i>>j)&1 :
            nowprice += price[j];
            for k in range(m) :
                allrikai[k] += rikai[j][k];
    check = 1;
    for j in range(m) :
        if allrikai[j] < x :
            check = 0;
            break;
    if check and nowprice <= ans :
        able = 1;
        ans = nowprice;

if able :
    print(ans);
else :
    print(-1);

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

alist = []
clist = []

for i in range(n):
  q = list(map(int,input().split()))
  alist.append(q[1:])
  clist.append(q[0])
  
total = sum(clist)
ans = float('inf')

def plus(x, y):
  return x+y


for i in range(2**n):
    money = 0 
    sum = [0]*m

    for j in range(n):
        if (i>>j)&1:
            sum = list(map(plus, sum, alist[j]))
            money += clist[j]

    for k in range(m):
      if sum[k] < x:
        break
    else:
      if ans >= money:
        ans = money

        
if ans <= total:
  print(ans)
else:
  print(-1)

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

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

over_set = list()
for ii in range(2 ** N):
    a_sum = [0 for _ in range(M)]
    for j in range(N):
        if (ii >> j) & 1:
            for k in range(1, M+1):
                a_sum[k-1] += aa_list[j][k]
    
    flag = True
    for k in range(M):
        if a_sum[k] < X:
            flag = False
    if flag:
        over_set.append(ii)

if len(over_set) == 0:
    print(-1)
else:
    min_val = 10**5 * N +3
    for ii in over_set:
        
        sum_val = 0
        for j in range(N):
            if (ii >> j) & 1:
                sum_val += aa_list[j][0]
        min_val = min(min_val, sum_val)

    print(min_val)

Solution (Python):
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


import itertools

n, m, k = multi_int_input()

stuff = [x for x in range(0, n)]

a = []

for i in range(n):
    b = list_input()
    a.append(b)

ans = 9999999999999999

def calculate(arr):
    ax = [0 for i in range(m+1)]
    cost = 0
    for j in arr:
        for i in range(1,m+1):
            ax[i] += a[j][i]
        cost+= a[j][0]
    for j in range(1, m+1):
        if ax[j] < k:
            return 9999999999999999
    return cost

for L in range(0, len(stuff)+1):
    for subset in itertools.combinations(stuff, L):
        
        ans = min(ans, calculate(subset))
        

if ans == 9999999999999999:
    ans = -1

print(ans)