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(i) for i in input().split())
l=[]
ans=None
for i in range(n):
  l.append([int(i) for i in input().split()])
for i in range(2**n):
  k=i
  r=[0 for i in range(m)]
  cost=0
  for j in range(n):
    if k%2==1:
      for y in range(m):
        r[y]+=l[j][y+1]
      cost+=l[j][0]
    k=k//2
  if min(r)>=x:
    if ans==None:
      ans=cost
    elif ans>cost:
      ans=cost
if ans==None:
  print('-1')
else:
  print(ans)

Solution (Python):
n, m, x = map(int, input().split())
ca_list = [[int(i) for i in input().split()] for _ in range(n)]
ans = 999999999999999
flag = 0

for i in range(2**n):
  bin_str = format(i, '0'+str(n)+'b')
  skill_list = [0]*m
  cost = 0
  for j, ca in enumerate(ca_list):
    if bin_str[j] == "1":
      cost += ca[0]
      for k in range(m):
        skill_list[k] += ca[k+1]
  if all([i >= x for i in skill_list]):
    ans = min(ans, cost)
    flag = 1
print(ans if flag == 1 else -1)

Solution (Python):
import sys


N, M, X = map(int, input().split())
A = [None] * N
C = [None] * N
for i, s in enumerate(sys.stdin.readlines()):
    C[i], *A[i] = map(int, s.split())

ans = 10 ** 8
for i in range(1 << N):
    k = 0
    v = 0
    S = [0] * M
    while (i >> k) > 0:
        if (i >> k) & 1:
            for j in range(M):
                S[j] += A[k][j]
            v += C[k]
        k += 1

    if all(a >= X for a in S):
        ans = min(ans, v)
        

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

Solution (Python):
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, M, X = [int(x) for x in input().strip().split()]
    C = [0] * N
    A = [[0 for _ in range(M)] for _ in range(N)]
    for n in range(N):
        ca = [int(x) for x in input().strip().split()]
        C[n] = ca[0]
        A[n] = ca[1:]
    ans = float('inf')
    for i in range(1 << N):
        A_ = [0] * M
        ans_ = 0
        for j in range(N):
            if i >> j & 1 == 1:
                for m in range(M):
                    A_[m] += A[j][m]
                ans_ += C[j]
        f = True
        for m in range(M):
            if A_[m] < X:
                f = False
                break
        if f:
            ans = min(ans, ans_)
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
N, M, X = [int(i) for i in input().split()]
ans = float("inf")
CA = [[int(i) for i in input().split()] for _ in range(N)]
for i in range(1, N + 1):
    for j in combinations(list(range(N)), i):
        ary = [0 for _ in range(M)]
        c = 0
        for k in j:
            c += CA[k][0]
            for i, l in enumerate(CA[k][1:]):
                ary[i] += l
        if all([x >= X for x in ary]):
            ans = min(c, ans)
print(ans if ans < float("inf") else -1)

Solution (Python):
n,m,x=map(int,input().split())
cc=[list(map(int,input().split())) for _ in range(n)]
from itertools import combinations
s=list(range(n))
ans=10**10
array=[0]*m
res=0
for ii in range(1,n+1):
    for i in combinations(s,ii):
        for j in i:
            res+=cc[j][0]
            for k,l in enumerate(cc[j][1:]):
                array[k]+=l
        if min(array)>=x:
            ans=min(ans,res)
        res=0
        array=[0]*m
    
if ans==10**10:
    print(-1)
else:
    print(ans)

Solution (Python):
import itertools
import numpy as np

n, m, x = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for _ in range(n)]
costs = [i[0] for i in table]
acc = [i[1:] for i in table]

ret = 10 ** 9
for i in itertools.product([True, False], repeat=n):
  algos = np.zeros(m)
  for book, t_f in enumerate(i):
    if t_f:
      algos += acc[book]
  if np.all(algos >= x):
    ret = min(ret, (np.array(costs) * i).sum())

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

Solution (Python):

import numpy as np


def solve(*args: str) -> str:
    n, m, x = map(int, args[0].split())
    inf = 10**12

    C = []
    A = []
    for CA in map(str.split, args[1:]):
        C.append(int(CA[0]))
        A.append(CA[1:])

    A = np.array(A, int)

    ret = inf
    for b in range(2**n):
        S = np.zeros(m, int)
        c = 0
        for i in range(n):
            if (b >> i) & 1 == 1:
                S += A[i]
                c += C[i]
            if all(x <= S):
                ret = min(ret, c)

    return str(ret if ret < inf else -1)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
import itertools
N, M, X = map(int, input().split())
C = []
A = []
ans = -1
for i in range(N):
  tmp = list(map(int, input().split()))
  C.append(tmp[0])
  A.append(tmp[1:])
for bit in itertools.product([0,1], repeat=N):
  tmpX = [0 for _ in range(M)]
  tmpC = 0
  for i in range(N):
    if bit[i] == 1:
      for j in range(M):
        tmpX[j] += A[i][j]
      tmpC += C[i]
  flag = True
  for i in range(M):
    if tmpX[i] < X:
      flag = False
      break
  if not flag:
    continue
  if ans == -1:
    ans = tmpC
  else:
    ans = min(ans, tmpC)
print(ans)

Solution (Python):
n,m,x=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
cursor=n
current=[0]*n
mincost=1000000000000000000000
breakflag=0
while True:
  thing=[0]*m
  cost=0
  for i in range(n):
    if current[i]==1:
      cost+=a[i][0]
      for j in range(m):
        thing[j]+=a[i][j+1]
  success=1
  for j in range(m):
    if thing[j]<x:
      success=0
  if success==1 and cost<mincost:
    mincost=cost
  while True:
    if current[cursor-1]<1:
      current[cursor-1]+=1
      for i in range(cursor,n):
        current[i]=0
      cursor=n
      break
    cursor-=1
    if cursor==0:
      breakflag=1
      break    
  if breakflag==1:
    break
if mincost==1000000000000000000000:
  print(-1)
else:
  print(mincost)

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

ans = -1
for bits in range(2 ** N):
    cost = 0
    param = [0] * M
    for i in range(N):
        if (bits >> i) & 1 == 1:
            cost += CA[i][0]
            for j in range(M):
                param[j] += CA[i][j + 1]

    if min(param) >= X:
        ans = min(ans, cost) if ans != -1 else cost

print(ans)

Solution (Python):
import sys
l = sys.stdin.readline().strip()
N, M, X = map(int, l.split())
A = []
C = []
for i in range(N):
    l = sys.stdin.readline().strip()
    a = list(map(int, l.split()))
    C.append(a[0])
    A.append(a[1:])

price = float("INF")
for i in range(2**N):
    bits = bin(i)[2:]
    while len(bits) < N:
        bits = '0' + bits
    bits = list(bits)
    good = True
    for j in range(M):
        crt = 0
        for k, b in enumerate(bits):
            if b == '1':
                crt += A[k][j]
        if crt < X:
            good = False
            break
    if good:
        p = 0
        for k,b in enumerate(bits):
            if b == '1':
                p += C[k]
        if p < price:
            price = p

if price == float("INF"):
    print(-1)
else:
    print(price)

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

import numpy as np
import itertools
from collections import defaultdict

l   = list(range(N))
c   = 0
d   = defaultdict(list)
for i in range(1, N+1):
    for j in itertools.combinations(l, i):
        d[c] = list(j)
        c    += 1

Y = np.zeros((N, M+1), dtype=int)

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

res = []
for i in range(c):
    j   = Y[d[i]].sum(0)
    if np.sum(np.r_[j[1:]] >= X) == M:
        res.append(j[0])

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

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math

import itertools
import heapq


import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default




def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n,m,x=map(int,input().split())
    c=[]
    a=[]
    for i in range(n):
        temp=list(map(int,input().split()))
        c.append(temp[0])
        a.append(temp[1:])
    total=INFI
    for i in itertools.product(range(2),repeat=n):
        tempkin=0
        rik=[0 for _ in range(m)]
        for ii in range(n):
            for iii in range(m):
                if i[ii]==1:
                    rik[iii]+=a[ii][iii]
            if i[ii]==1:
                tempkin+=c[ii]
        ans=1
        for j in range(m):
            if rik[j]<x:
                ans=0
                break
        if ans==1:
            total=min(total,tempkin)
    if total==INFI:
        print(-1)
    else:
        print(total)








if __name__ == "__main__":

    main()

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

for i in range(1 << N):
    tmp = [0] * M
    money = 0
    flag = True
    for j in range(N):
        if i & (1 << j):
            money += C[j]
            for k in range(M):
                tmp[k] += A[j][k]
    for j in range(M):
        if tmp[j] < X:
            flag = False
            break
    if flag:
        ans.append(money)

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

Solution (Python):
import sys
from itertools import product
def input(): return sys.stdin.readline().rstrip()

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

    ans = -1
    bit_list = list(product([0, 1], repeat=N))
    for bits in bit_list:
        tmp_ans = 0
        m_list = [0] * M

        for ca, bit in zip(CA, bits):
            if bit == 0:
                continue
            tmp_ans += ca[0]
            if ans > 0 and tmp_ans > ans:
                break
            for i, v in enumerate(ca[1:]):
                m_list[i] += v
        if min(m_list) >= X:
            if tmp_ans < ans or ans < 0:
                ans = tmp_ans
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys
from itertools import combinations

def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n, m, x = _ia()
    c = []
    a = []
    for i in range(n):
        t = list(_ia())
        c.append(t[0])
        a.append(t[1:])
    books = [i for i in range(n)]
    r = -1
    for i in range(1,n+1):
        for b in combinations(books, i):
            cost = sum(c[k] for k in b)
            if r>0 and cost>=r:
                continue
            tmp = [0] * m
            for bi in b:
                for j,aij in enumerate(a[bi]):
                    tmp[j] += aij

            if min(tmp)>=x:
                r = cost
    return r

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

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


def solve(flags):
    global m, c, a
    points = [0] * m
    price = 0
    for i, f in enumerate(flags):
        if f == 1:
            price += c[i]
            for j in range(m):
                points[j] += a[i][j]
    cleared = list(filter(lambda p: p >= x, points))
    return price if len(cleared) == m else -1

answer = -1
for i in range(2 ** n):
    flags = list(map(int, list(bin(i)[2:].zfill(n))))
    result = solve(flags)
    if result > 0:
        if answer == -1:
            answer = result
        else:
            answer = min(result, answer)

print(answer)

Solution (Python):
global N, M, X
N, M, X = map(int, input().split())
global C, A
C, A = [], []
for i in range(N):
    tmp, *_ = map(int, input().split())
    C.append(tmp), A.append(list(_))
    
def adde(a, b):
    t = []
    for i in range(M):
        t.append(a[i] + b[i])
    return t
        


def solve(times, big, lists, cost):
    if times == N:
        if not len(list(filter(lambda x:x<X, lists))):
            return min(big, cost)
        else:
            return big

    big = solve(times + 1, big, adde(lists, A[times]), cost + C[times])
    big = solve(times + 1, big, lists, cost)
    
    return big

ans = solve(0, float('inf'), [0 for i in range(M)], 0)
print(ans if ans != float('inf') else -1)

Solution (Python):
import itertools


n, m, x = [int(_) for _ in input().split()]
l = []
for i in range(n):
    l.append([int(_) for _ in input().split()])



p = []
for i in range(n):
    p.append(i)
ans = float('inf')
for i in range(1, n+1):
    for q in list(itertools.combinations(p, i)):
        flag = 0
        c = 0
        sum = [0] * m
        for j in range(len(q)):
            for k in range(m):
                
                
                sum[k] += l[q[j]][k+1]
            c += l[q[j]][0]
        
        
        
        for y in range(m):
            if sum[y] < x:
                flag = 1
        if flag == 0:
            ans = min(ans, c)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
n , m , x = map(int, input().split())
b = [list(map(int,input().split())) for i in range(n)]
s = [list(map(int,bin(x)[2:].zfill(n))) for x in range(2**n)]
mi = 10000000
check = 1
for i in s:
    price=0
    a=[0]*m
    for j in range(n):
        price+=i[j]*b[j][0]
        for k in range(m):
            a[k]+=i[j]*b[j][k+1]
    for l in range(m):
        if a[l]<x:
            check=0
    if check == 1:
        mi=min(price,mi)
    check=1
if mi == 10000000:
    print("-1")
else:
    print(mi)

Solution (Python):
from itertools import product

INF = 10**10
n,m,x = map(int,input().split())
C = [0]*n
A = [[0]*m for _ in range(n)]
for i in range(n):
  T = list(map(int,input().split()))  
  C[i] = T[0]
  A[i] = T[1:]
 
prd = product([1,0],repeat = n)

ans = INF
for pr in prd:
  tmp = [0]*m
  cost = 0
  for i in range(n):
    if pr[i]:
      cost += C[i]
      for j in range(m):
        tmp[j] += A[i][j]
  if all([t>=x for t in tmp]):
    ans = min(cost,ans)
  
if ans == INF:
  print(-1)
else:
  print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, M, X = map(int, input().split())
    cost = 10**10
    cost_choose = 0
    books = []
    for _ in range(N):
        books.append(list(map(int, input().split())))
    

    for choose in range(1<<N):
        val = 0
        skill = [0] * (M+1)
        for i in range(N):
            if choose & (1 << i) != 0:
                val += books[i][0]
                for j in range(1, M+1):
                    skill[j] += books[i][j]
        accomp = True
        for j in range(1, M+1):
            if skill[j] >= X:
                continue
            else:
                accomp = False
                break
        
        if accomp:
            cost = min(cost, val)
            cost_choose = choose

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


if __name__ == "__main__":
    main()

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m,x = readInts()
    ans = float('inf')
    money = []
    rikai = []
    for i in range(n):
        LIST = readInts()
        money.append(LIST[0])
        rikai.append(LIST[1:])
    
    
    for bit in range(1 << n):
        mo = 0
        ansrikai = [0] * m
        for i in range(n):
            if bit & (1 << i):
                mo += money[i]
                for j in range(m):
                    ansrikai[j] += rikai[i][j]
        ok = True
        
        for j in range(m):
            if ansrikai[j] >= x:
                ok = True
            else:
                ok = False
                break
        if ok:
            
            ans = min(ans,mo)
    print(ans if ans != float('inf') else -1)
if __name__ == '__main__':
  main()

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    N, M, X = readnums()
    ca = [list(readnums()) for _ in range(N)]
    ans = 0
    for i in range(1, 2 ** N):
        c = bin(i)[2:]
        c = '0' * (N - len(c)) + c
        tmp = 0
        tmpl = []
        for i, x in enumerate(c):
            if int(x):
                if not tmpl:
                    tmpl += ca[i]
                else:
                    tmpl = [a + b for a, b in zip(tmpl, ca[i])]

                if all([i >= X for i in tmpl[1:]]):
                    tmp = tmpl[0]
                    if not ans:
                        ans = tmp
                    else:
                        ans = min(ans, tmp)

    print(ans if ans else -1)


if __name__ == "__main__":
    main()

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

ans = None

for i in range(1, N+1):
    for comb_list in combinations(CA, i):
        comb_list = np.array(comb_list)
        sum_list = comb_list.sum(axis=0)
        if np.all(sum_list[1:] >= X):
            if not ans or (ans > sum_list[0]):
                ans = sum_list[0]
print(-1 if ans is None else ans)

Solution (Python):
N, M, X = map(int, input().split())
li_a = []
li_c = []
for _ in range(N):
    temp = list(map(int, input().split()))
    li_temp = []
    for i in range(len(temp)):
        if i == 0:
            li_c.append(temp[i])
        else:
            li_temp.append(temp[i])
    li_a.append(li_temp)
min_ = 10**15
for s in range(1<<N):
    money = 0
    dic = {}
    for i in range(M):
        dic[i] = 0
    for j in range(N):
        if (1<<j) & s:
            money += li_c[j]
            for k in range(len(li_a[j])):
                dic[k] += li_a[j][k]
    b = True
    for i in range(M):
        if dic[i] < X:
            b = False
            break
    if b:
        min_ = min(min_, money)
    
if min_ == 10**15:
  print(-1)
else:
    print(min_)

Solution (Python):
n,m,k = map(int,input().split())
a=[]
costs=[]
for _ in range(n):
    nl = list(map(int,input().split()))
    costs += [nl[0]]
    nl = nl[1:]
    a += [nl]

from itertools import product

ans = 10**16

for i in range(2**n):
    f = bin(i)[2:]
    f = "0"*(n-len(f)) + f
    f = [int(k) for k in f]
    total = [0]*m
    cost = 0
    for i in range(n):
        if f[i]:
            cost += costs[i]
            for j in range(m):
                total[j] += a[i][j]
    if min(total) >= k:
        ans = min(ans, cost)

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

Solution (Python):

from itertools import*
n, m, x = map(int, input().split())
d = [list(map(int, input().split())) for k in range(n)]
INF = float("inf")
mi = INF
for i in range(1, n+1):
    for j in combinations(range(n), i):
        if all(sum(d[p][q] for p in j) >= x for q in range(1, m+1)):
            mi = min(mi, sum(d[c][0] for c in j))
print(mi if mi != INF else -1)

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

C = []
A = []

for i in range(N):
    c, *a = [int(n) for n in input().split()]
    C.append(c)
    A.append(a)



mc = -1
for k in range(2**N):
    kk = k
    rikai = [0] * M
    cost = 0
    for i in range(N):
        if kk & 1:
            cost += C[i]
            rikai = [r + a for (r, a) in zip(rikai, A[i])]
            if all([r >= X for r in rikai]):
                if mc == -1 or mc > cost:
                    mc = cost
        kk >>= 1

print(mc)

Solution (Python):
N, M, X = map(int, input().split())
books = [tuple(map(int, input().split())) for _ in range(N)]
MAX = 10**12
ans = MAX
for bit in range(1 << N):
    money = 0
    algo = [0] * M
    for i in range(N):
        if ((bit >> i) & 1) == 1:
            C, *A, = books[i]
            money += C
            for j, a in enumerate(A): algo[j] += a
    if any(a < X for a in algo): continue
    ans = min(ans, money)
print(ans if ans != MAX else -1)

Solution (Python):
N, M, X = map(int, input().split())
book = []
cost = []
for i in range(N):
    c, *a, = list(map(int, input().split()))
    book.append(a)
    cost.append(c)
ans = float('inf')
for bit in range(1 << N):
    know = [0] * M
    costbit = 0
    flag = True
    for i in range(N):
        if bit & (1 << i):
            for j in range(M):
                know[j] += book[i][j]
            costbit += cost[i]
    for l in range(M):
        if know[l] < X:
            flag = False
    if flag:
        ans = min(ans, costbit)
if ans <= 1000000000:
    print(ans)
else:
    print(-1)

Solution (Python):
"""
algo1 algo2 algo3 
 0     0     0
"""
n, m, x = map(int, raw_input().split(' '))
books = [map(int, raw_input().split(' ')) for _ in range(n)]

def dfs(i, books, x, cc, knowledge, r):
	if i == len(books):
		if all([k>= x for k in knowledge]):
			r[0] = min(r[0], cc)
		return

	u = books[i]
	cost = u[0]
	book = u[1:]
	improvedknowledge = [k+book[ii] for ii,k in enumerate(knowledge)]
	
	dfs(i+1, books, x, cc + cost, improvedknowledge, r)
	dfs(i+1, books, x, cc, knowledge[::], r)

r = [+float('inf')]
dfs(0, books, x, 0, [0] * m, r)
print r[0] if r[0] < float('inf') else -1

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, M, X = LI()
    C = [0]*N
    A = [[0]*M for _ in range(N)]
    for i in range(N):
        ca = LI()
        C[i] = ca[0]
        A[i] = ca[1:]

    cost_min = INF
    for i in range(2**N):
        cost = 0
        rikaido = [0]*M
        for j in range(N):
            if i>>j&1:
                cost += C[j]
                rikaido = [k+m for k, m in zip(rikaido, A[j])]
        if [j>=X for j in rikaido].count(True)==M:
            cost_min = min(cost, cost_min)

    if cost_min>=INF:
        print(-1)
    else:
        print(cost_min)

if __name__ == '__main__':
    resolve()

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

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

Solution (Python):


from itertools import chain, combinations

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

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

print(min((sum(c[i] for i in s) for s in powerset(range(n))
           if all(sum(a[i][j] for i in s) >= x for j in range(m))),
          default=-1))

Solution (Python):


from itertools import chain, combinations

def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

[n, m, X] = map(int, input().split())
c = [0 for x in range(n)]
a = [[0 for x in range(m)] for y in range(n)]

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

costs = []
for s in powerset(range(n)):
    cost = 0
    t = [0 for x in range(m)]
    for x in s:
        cost += c[x]
        for y in range(m):
            t[y] += a[x][y]
    if all(map(lambda x: x >= X, t)):
        costs.append(cost)

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

Solution (Python):
n, m, x = map(int, input().split())
min_c = float('inf')
l = []
for i in range(n):
    ns = list(map(int, input().split()))
    l.append(ns)
for i in range(1, 2 ** n):
    flag = True
    a = bin(i)[2:].zfill(n)
    for j in range(m):
        s = 0
        for index, b in enumerate(a):
            if b == '1':
                s += l[index][j+1]
        if s < x:
            flag = False
            break
    if flag:
        min_c = min(min_c, sum(l[i][0] for i in range(n) if a[i] == '1'))
if min_c == float('inf'):
    print(-1)
else:
    print(min_c)

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
ca = [[int(i) for i in readline().split()] for _ in range(n)]

from itertools import combinations
import numpy as np

lc = [i for i in range(n)]

ans = 1001001001

for nc in range(1,n+1):
    lc_sub = list(combinations(lc,nc))
    for lc_sub2 in lc_sub:
        tmp_price = 0
        tmp_und = np.array([0]*m)
        for c in lc_sub2:
            tmp_price += ca[c][0]
            tmp_und += np.array(ca[c][1:])
        if all([und >= x for und in tmp_und]):
            ans = min(ans, tmp_price)

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

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

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

for i in range(2**N):
    l = [0]*M
    cst = 0
    flag = True
    for j in range(N):
        if (i>>j) & 1:
            cst += C[j]
            for k in range(M):
                l[k] += A[j][k]
    for k in range(M):
        if l[k] < X:
            flag = False
            break
    if flag:
        if cst < min_cst or min_cst == -1:
            min_cst = cst

print(min_cst)

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

mini = 12 * 100000 + 1
for bit in range(1<<N):
    A_sum = [0] * M
    price = 0
    for i in range(N):
        if (bit >> i) & 1:
            price += C[i]
            for j in range(M):
                A_sum[j] += A[i][j]
    flug = True
    for i in A_sum:
        if i < X:
            flug = False
            break
    if flug:
        mini = min(mini, price)
if mini == 12 * 100000 + 1: print(-1)
else: print(mini)

Solution (Python):
import sys
input = sys.stdin.readline
N, M, X = list(map(int, input().split()))

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

ans = float('inf')

for i in range(2**N):
    cost = 0
    A = [0] * M
    for j in range(N):
        if i >> j & 1 == 1:
            cost += CA[j][0]
            for m in range(M):
                A[m] += CA[j][m+1]

    flg = True
    for m in range(M):
        if A[m] < X:
            flg = False
            break
    if flg:
        ans = min(ans, cost)

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

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

from itertools import combinations
a = []
for i in range(n):
    a.append([int(i) for i in input().split(' ')])
min_cost = float('inf')
for i in range(1, n + 1):
    for opt in combinations(range(n), i):
        curr_cost = 0
        curr_skills = [0] * m
        for to_take in opt:
            curr_cost += a[to_take][0]
            for j in range(1, m + 1):
                curr_skills[j - 1] += a[to_take][j]
        found = True
        for j in range(m):
            if curr_skills[j] < x:
                found = False
        if found:
            min_cost = min(min_cost, curr_cost)
print(min_cost if min_cost != float('inf') else -1)

Solution (Python):
import numpy as np
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
ca=np.array(ca)
ans=np.array([])
ans_list=np.array([])
for i in range(2**n):
  flag=True
  ans=np.array([0]*(m+1))
  for j in range(n):
    if (i>>j)&1:
      ans+=ca[j]
  for i in range(1,len(ans)):
    if x>ans[i]:
      flag=False
      break
  if flag==True:
    ans_list=np.append(ans_list,ans[0])
if len(ans_list)>=1:
  print(int(min(ans_list)))
else:
  print(-1)

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

cs = []
a = []
for i in range(n):
    inputs = [int(x) for x in input().split()]
    ci = inputs[0]
    ai = inputs[1:]
    cs.append(ci)
    a.append(ai)

res = 99999999999
for num in itertools.product('01', repeat=n):
    tmp = np.zeros(m)
    cost = 0
    for j in range(n):
        if num[j] == '0':
            continue
        else:
            cost += cs[j]
            tmp += np.array(a[j])
    if sum(tmp >= x) == m:
        flag = 1
        res = min(res, cost)

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