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 numpy as np

n,m,x = [int(i) for i in input().split()]
costs =[]
maa = 1000000000000000000000000000
ans = maa

for i in range(n):
    a = [int(i) for i in input().split()]
    costs.append(a)
    
for i in range(1,2**n+1):
    cost = 0
    c = 0
    sums = [0] * m
    use_index=[]
    for j in range(n):
        if i%2==1:
            use_index.append(j)
        i >>= 1
    
    for v in use_index:
        c += costs[v][0]        
        for j in range(m):
            sums[j] += costs[v][j+1]
            
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)

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

Solution (Python):


import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys


def S():
    return sys.stdin.readline().rstrip()


def I():
    return int(sys.stdin.readline().rstrip())


def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))


def LS():
    return list(sys.stdin.readline().rstrip().split())


def num2ary(n, num):
    ret = [0] * n
    x = 2 ** (n - 1)
    for i in range(n):
        if x <= num:
            num = num - x
            ret[i] = 1
        else:
            ret[i] = 0
        x = x / 2
    return ret


def main():
    n, m, x = LI()
    
    c = []
    a = [[0] * m] * n
    
    for i in range(n):
        z = LI()
        
        c.append(z[0])
        
        a[i] = z[1:]
        
    cmin = 9999999999
    for i in range(2 ** n):
        csum = 0
        asum = [0] * m
        ary = num2ary(n, i)
        for j in range(n):
            if ary[j] == 1:
                csum = csum + c[j]
                for k in range(m):
                    asum[k] = asum[k] + a[j][k]
        
        ok = 1
        for i in range(m):
            if asum[i] < x:
                ok = 0
                break
        if ok == 1 and csum < cmin:
            cmin = csum
            
    if cmin >= 9999999999:
        print(-1)
    else:
        print(cmin)
    
    


main()

Solution (Python):
import numpy as np
n,m,x=map(int,input().split())
c=[0]*n
a=[0]*n
for i in range(n):
  tmp=list(map(int,input().split()))
  c[i]=tmp[0]
  a[i]=tmp[1:]
price=sum(c)+1
for i in range(2**n):
  now_p=0
  score=np.zeros(m)
  
  for j in range(n):  
    if ((i >> j) & 1):
      score = score + np.array(a[j])
      now_p+=c[j]
  if np.count_nonzero(score < x) == 0 and price > now_p:
    price = now_p

if price < sum(c) +1:
  print(price)
else:
  print(-1)

Solution (Python):
import itertools
import numpy as np


N, M, X = map(int, input().split())
books = np.array([list(map(int, input().split())) for i in range(N)])
minsum = N * 10**5
count = 0
check_array = []
success_array = []
for x in range(1, N + 1, 1):
    combi_list = list(itertools.combinations(range(N), x))
    for y in combi_list:
        sum_array = [0] * (M + 1)
        for z in y:
            sum_array = sum_array + books[z]
        beyond_check = True
        for zz in range(len(sum_array) - 1):
            if sum_array[zz + 1] < X:
                beyond_check = False
                break
        if beyond_check:
            success_array.append(sum_array[0])

    lenlist = len(combi_list)
    count += lenlist
if len(success_array) > 0:
    print(min(success_array))
else:
    print(-1)

Solution (Python):
N, M, XX = (int(i) for i in input().split())  

C = []
X = []
for _ in range(N):
    tmp = [int(i) for i in input().split()] 
    c = tmp[0]
    x = tmp[1:]
    C.append(c)
    X.append(x)

totalC = 10000000000000000
for ho in range((2 ** N)):
    tmp_c = 0
    tmp_x = [0] * (M)

    tmp = format(ho, '013b')[13-N:]
    for i in range(len(tmp)):
        if tmp[i] == "1":
            tmp_c += C[i]
            for ii in range(M):
                tmp_x[ii] += X[i][ii]


    flag = True
    for fu in tmp_x:
        if fu < XX:
            flag = False
    
    if flag & (tmp_c < totalC):
        totalC = tmp_c

if totalC == 10000000000000000:
    print("-1")
else:
    print(totalC)

Solution (Python):
from itertools import combinations

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

l=[list(map(int,input().split())) for _ in range(n)]
cost=float("inf")

for i in range(1,n+1):
    for l1 in combinations(l,i):
        score = [0]*m
        cost1=0

        for l2 in l1:
            cost1 += l2[0]
            for j in range(1,m+1):
                score[j-1] += l2[j]

        if min(score) >= x:
            cost = min(cost,cost1)

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

Solution (Python):
n,m,x = map(int,input().split())
san = list(tuple(map(int, input().split())) for _ in range(n))
dp = [float('inf')]*(1<<n)
ans = float('inf')
for i in range(1<<n):
    dai = 0
    ri = [0]*m
    for j in range(n):
        if i&(1<<j):
            dai += san[j][0]
            for k in range(1,m+1):
                ri[k-1] += san[j][k]
    for r in range(m):
        flag = True
        if ri[r]<x:
            flag = False
            break
    if flag:
        ans = min(ans, dai)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
import itertools
N,M,X = list(map(int, input().split()))
C = [0 for i in range(N)]
A = [[0 for j in range(M)] for j in range(N)]
for i in range(N):
    A_ = list(map(int, input().split()))
    C[i] = A_[0]
    for j in range(M):
      A[i][j] = A_[j+1]
      
def check(books):
    algos_point = [0]*M
    for i in books:
        for j in range(M):
            algos_point[j] = algos_point[j] + A[i][j]
    for j in range(M):
        if algos_point[j] < X:
            return False
    return True

def cost(books):
    val = 0
    for i in books:
        val = val + C[i]
    return val
  
combi = []
for i in range(1,N+1):
    combi += list(itertools.combinations(list(range(N)), i))

vals = []
for c in combi:
  if check(c):
    vals.append(cost(c))
        
if vals == []:
  print(-1)
else:
  print(min(vals))

Solution (Python):
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)


inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""

from collections import deque
from itertools import product
import numpy as np
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))



def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():

    N, M, X = wi()
    A = []
    for _ in range(N):
        A.append(wi())
    ans = 10**20
    flag = False
    for t in product([0, 1], repeat=N):
        plus = [0] * (M+1)
        plus = np.array(plus)
        flag = False
        for i in range(len(t)):
            if t[i] == 0:
                continue
            else:
                plus += np.array(A[i])
                
        for j in range(1, M+1):
            if plus[j] < X:
                flag = True
                break
        if flag == False:
            ans = min(ans, plus[0])

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


if __name__ == '__main__':
    main()

Solution (Python):
n,m,x=map(int,input().split())
ca=[]
ans=float('inf')
for _ in range(n):
    ca.append(list(map(int,input().split())))
for i in range(2**n):
    money=0
    check=[0]*(m)
    for j in range(n):
        if ((i>>j)&1):
            money+=ca[j][0]
            for k in range(m):
                check[k]+=ca[j][k+1]
    if all(check[p]>=x for p in range(m)):
        ans=min(ans,money)
if ans==float('inf'):
    print('-1')
else:
    print(ans)

Solution (Python):
import itertools

n,m,x = map(int, input().split(" "))
infolist = []
for i in range(n):
  infolist.append(list(map(int, input().split(" "))))
  
optionlist = list(itertools.product('AB', repeat=n))

moneylist = []

for option in optionlist:
  knowledge = [0]*m
  money = 0
  
  for i in range(n):
    if option[i]=="A":
      
      for k in range(m):
        knowledge[k] += infolist[i][k+1]
      money += infolist[i][0]
  
  if all([p >= x for p in knowledge]):
    moneylist.append(money)

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

Solution (Python):
import itertools

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

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

allbooks = [sum([j[i] for j in CA]) for i in range(M+1)]


if min(allbooks[1:]) < X:
    print(-1)
else:
    kingaku = allbooks[0]
    yobun = [i-X for i in allbooks[1:]]

    maxkingaku = 0
    go = True
    for k in range(1, N):
        if go == False:
            break
        allicombi = itertools.combinations(CA, k)
        OKs = 0
        for combi in allicombi:
            goukei = [sum([j[i] for j in combi]) for i in range(M+1)]
            if min([y-x for x,y in zip(goukei[1:], yobun)])>=0:
                OKs +=1
                if goukei[0] > maxkingaku:
                    maxkingaku = goukei[0]

        if OKs == 0:
            go = False
    print(kingaku - maxkingaku)

Solution (Python):
import numpy as np
n,m,x = map(int, input().split())
c_a = [list(map(int, input().split())) for _ in range(n)]
argo_und = []
ans = 12*(10**5)
for i in range(2 ** n):
    flag = 0
    sums = np.zeros(m+1)
    for j in range(n):
        if ((i >> j) & 1):
            sums = sums + np.array(c_a[j])
    for j in range(1,m+1):
        if sums[j] < x:
            flag = 1
    if flag == 0:
        ans = min(ans, sums[0])
if flag == 1:
    print(-1)
else:
    print(int(ans))

Solution (Python):

"""
Created on Sun May 10 20:50:51 2020
"""

import sys

import itertools

sys.setrecursionlimit(10 ** 9)


mod = 10**9+7

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

ans = 10 ** 9
for i in range(1,N+1):
    for C in itertools.combinations(ca,i):

        tmp = 0
        m = [0 for _ in range(M)]
        for c in C:
            tmp += c[0]
            for i in range(M):
                m[i] += c[1+i]
        flg = True
        for mm in m:
            if mm < X:
                flg = False
        
        if flg:
            ans = min(ans,tmp)

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

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



bestmoney = float("inf")
for i in range(2**N):
    U = []
    for j in range(M):

        u = sum([(((1<<k)&i)!=0)*A[k][j] for k in range(N)])
        U.append(u)
    flag = True
    for j in range(M):
        if U[j] < X:
            flag = False
            

    if flag:
        bestmoney = min(sum([(((1<<k)&i)!=0)*C[k] for k in range(N)]), bestmoney)

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

Solution (Python):
import itertools
import numpy as np

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

coin = []
for i in range(1, n+1):
  for v in itertools.combinations(books, i):
    comb = list(v)
    result = np.sum(comb, axis = 0)
    
    flag = True
    for j in range(1,m+1):
      if result[j] < x:
        flag = False
        break
    if flag:
      coin.append(result[0])

if len(coin) > 0:
  coin.sort(reverse=False)
  print(coin[0])
else:
  print(-1)

Solution (Python):
import itertools


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



def can_reach(M, CA, X):
    understandig_list = [0] * M
    for CAi in CA:
        for j in range(1, len(CAi)):
            understandig_list[j - 1] += CAi[j] 

    can = all([understandig >= X for understandig in understandig_list])

    return can


if not can_reach(M, CA, X):
    print('-1')
    exit(0)

min_amount = 10 ** 5 * 12 + 1
for i in range(1, N + 1):
    combinations = itertools.combinations(range(N), i)

    for combination in combinations:
        understanding_list = [0] * M
        amount = 0
        for i in combination:
            for j in range(1, len(CA[i])):
                understanding_list[j - 1] += CA[i][j]
            amount += CA[i][0]

        
        is_reached = all([understanding >= X for understanding in understanding_list])
        if not is_reached: continue

        min_amount = min(amount, min_amount)

print(min_amount)

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

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

kanoucost = []
for i in range(2**n):
    ls = [0]*n
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = 1
    ability = [0]*(m+1)
    for k in range(len(ls)):
        new = [n * ls[k] for n in listA[k]]
        ability = [x + y for (x, y) in zip(ability, new)]

    if min(ability[1:]) >= x:
        kanoucost.append(ability[0])

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

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

moneys = []
skips = []

for i in range(1, 2**n):
  b = [int(_) for _ in list(format(i, '0{}b'.format(n)))]
  
  sums = [0]*m
  skip = [0]*m
  money = 0
  
  for j in range(n):
    if b[j] == 1:
      money += a[j][0]
      for k in range(m):
        sums[k] += a[j][k+1]
        if sums[k] >= x:
          skip[k] = 1
  if sum(skip) == m:
    moneys.append(money)
if len(moneys) > 0:
  print(min(moneys))
else:
  print(-1)

Solution (Python):
n,m,x = map(int,input().split())
t = [0]*(m+1)
l = []
for i in range(n):
    l.append(list(map(int,input().split())))
    for j in range(m+1):
        t[j] += l[i][j]
p = 0
for i in range(1,m+1):
    if(t[i] < x):
        p = 1
        break
if(p == 1):
    print(-1)
else:
    c = t[0]
    for i in range(1,2**n):
        s = t.copy()
        z = str(bin(i)[2:])
        z = '0'*(n-len(z)) + z
        for j in range(n):
            if(z[j] == '0'):
                for k in range(m+1):
                    s[k] -= l[j][k]
        p = 0
        for j in range(1,m+1):
            if(s[j] < x):
                p = 1
                break
        if(p == 0):
            if(s[0] < c):
                c = s[0]
    print(c)

Solution (Python):
n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
mini = float('inf')
f=0

for i in range(2**n):
    v = [0]*m
    total = 0
    flag=0
    for j in range(n):  
        if ((i >> j) & 1):
            for k in range(m):
                v[k]+=a[j][k+1]
            total += a[j][0]
    for k in range(m):
        if v[k] < x:
            flag=1
    if flag == 0 and mini > total:
        mini = total
        f=1
        
if f == 0:
    print("-1")
else :
    print(int(mini))

Solution (Python):
import numpy as np

n, m, x = map(int, input().split(" "))
c_min = np.inf
input_list = list(map(int, input().split(" ")))
c_list = np.array([input_list[0]])
a_list = np.array([input_list[1:]])
for _ in range(n - 1):
    input_list = list(map(int, input().split(" ")))
    c_list = np.append(c_list, input_list[0])
    a_list = np.vstack([a_list, input_list[1:]])

for i in range(1, 2 ** n):
    i_bin_str = str(bin(i))[2:]
    if len(i_bin_str) < n:
        i_bin_str = "0" * (n - len(i_bin_str)) + i_bin_str
    i_bin_list = np.array(list(map(int, list(f"{i_bin_str}"))))
    if len(a_list[i_bin_list > 0]) > 1:
        a_min = min(sum(a_list[i_bin_list > 0]))
    else:
        a_min = min(a_list[i_bin_list > 0][0])
    c_sum = sum(c_list[i_bin_list > 0])
    if a_min >= x and c_sum < c_min:
        c_min = c_sum

ans = -1 if np.isinf(c_min) else c_min
print(ans)

Solution (Python):
import sys
from math import log2,floor,ceil,sqrt

sys.setrecursionlimit(10**5)


Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

def backtrack(arr,cur,ans):
    if cur == n:
        alg = [0]*m
        cost  = 0
        for i in range(len(arr)):
            if arr[i] == 1:
                cost+=c[i]
                for j in range(m):
                    alg[j] += lis[i][j]
        flag = True
        for i in range(m):
            if alg[i] < k:
                flag = False
                break
        if flag :
            ans[0] = min(ans[0],cost)
        return
    arr[cur] = 0
    backtrack(arr,cur+1,ans)
    arr[cur] = 1
    backtrack(arr,cur+1,ans)
    arr[cur] = 0

n,m,k  = Ri()
c = [0]*n
lis = []
for i in range(n):
    temp = Ri()
    c[i] = temp[0]
    lis.append(temp[1:])

arr = [0]*n
ans = [INF]
backtrack(arr,0,ans)
if ans[0] == INF:
    print(-1)
else:
    print(ans[0])

Solution (Python):
import sys
sys.setrecursionlimit(300000)
from math import isinf
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M, X = MI()
C = [0] * N
A = [list() for _ in range(N)]
for i in range(N):
    C[i], *A[i] = MI()

ans = INF
for bits in range(2 ** N):
    rikai = [0] * M
    cost = 0
    for i in range(N):
        if (bits >> i) & 1:
            cost += C[i]
            for j, a in enumerate(A[i]):
                rikai[j] += a
    if all(r >= X for r in rikai):
        ans = min(ans, cost)
if isinf(ans):
    print(-1)
else:
    print(ans)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.read

n, m, k = map(int, input().split())
ca = np.array(read().split(), dtype=np.int64).reshape([n,m+1])

ans = 10**8

for i in range(2**n):
    b = np.array(list(format(i,'0'+str(n)+'b')), dtype=np.int64)
    d = ca[b == 1].sum(axis=0)
    if np.all(d[1:] >= k):
        ans = min(ans, d[0])

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

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

next_list = []
for i in range(0,N):
    next_list.append(list(map(int, input().split())))
next_list = np.array(next_list)
min_tot = 10000000

def dfs(i,ab_list):
    global min_tot
    if i==N and np.all(ab_list[1:]>=nd_list):
        if min_tot > ab_list[0]:
            min_tot = ab_list[0]
        return True
    elif i ==N:
        return True

    dfs(i+1,ab_list)
    dfs(i+1,ab_list+next_list[i,:])


dfs(0,np.zeros(1+M))
if min_tot ==10000000:
    print(-1)
else:
    print(int(min_tot))

Solution (Python):
n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
import numpy as np

b = np.array(a)
total = []
for i in range(2**n):
    eff = np.array([0 for i in range(m)])
    money=0
    for j in range(n):
        if ((i >>j ) & 1):
            eff += b[j,1:]
            money+= b[j,0]
            if len(eff[eff>=x])==m:
                total.append(money)                
if len(total)==0:
    print(-1)
else:
    print(min(total))

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

study=[0]*m
ans=float("inf")
for i in range(2**n):
    study=[0]*m
    money=0
    for j in range(n):
        if (i>>j)%2 == 1:
            for k in range(m):
                study[k]+=a[j][k+1]
            money+=a[j][0]

    enough=True
    for k in range(m):
        if study[k]<x:
            enough=False
    if enough==True:
        ans=min(ans,money)

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

print(ans)

Solution (Python):
import copy
n, m, x = map( int, input().split() )
c = [ 0 ]
a = [[]]
for _ in range( n ):
    line = input().split()
    c = c + [ int( line[0] ) ]
    a = a + [ [ 0 ] + list( map( int, line[1:] ) ) ]



def search( understood, money, i ):
    if i > n:
        
        for j in range( 1, m+1 ):
            if understood[j] < x:
                return
        sum_money.append( money )
        return money
    else:
        search( understood, money, i+1 )
        next_understood = copy.deepcopy( understood )
        for j in range( 1, m + 1 ):
            next_understood[j] += a[i][j]
        next_money = money + c[i]
        search( next_understood, next_money, i+1 )

understood = [ 0 ] * ( m + 1 )
sum_money = []
search( understood, 0, 1 )


try:
    print( min( sum_money ) )
except ValueError:
    print( "-1" )

Solution (Python):
from itertools import product
N,M,X = map(int,input().split())
C = []
A = []
for n in range(N):
    a = list(map(int,input().split()))
    C.append(a[0])
    A.append(a[1:])
INF = 10**9
ans = INF
for p in product([0,1], repeat=N):
    sm = [0] * M
    cost = 0
    for i in range(N):
        if p[i]:
            for m in range(M):
                sm[m] += A[i][m]
            
            cost += C[i] 
    
    if min(sm) >= X:
        ans = min(ans,cost)
if ans==INF:
    print (-1)
else:
    print (ans)

Solution (Python):
N, M, X = list(map(int, input().strip().split()))
A, C = [], []
max_price = N * 10**5 + 1
ans = max_price

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

def dfs(current, choice):
  global ans
  
  if current == N:
    b, c = judge(choice)
    if b:
      ans = min(ans, c)
  else:
    choice[current] = False
    dfs(current+1, choice)
    choice[current] = True
    dfs(current+1, choice)
    
def judge(choice):
  c = 0
  score_list = [0] * M
  for k, v in enumerate(choice):
    if v:
      c += C[k]
      for k2, v2 in enumerate(score_list):
        score_list[k2] = v2 + A[k][k2]  
  b = True
  for s in score_list:
    if s < X:
      b = False
      break
  return b, c

dfs(0, [False] * N)
if ans == max_price:
  ans = -1
print(ans)

Solution (Python):
import itertools

n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=list(range(n))
c=[0]*(m+1)
d=[]
for i in range(1,n+1):
    for v in itertools.combinations(b,i):
        for j in v:
            for k in range(m+1):
                c[k]+=a[j][k]
        d.append(c)
        c=[0]*(m+1)
e=[]
for i in range(len(d)):
    ok=0
    for j in range(1,len(d[i])):
        if d[i][j]>=x:
            ok+=1
    if ok==m:
        e.append(i)

if len(e)==0:
    print(-1)
else:
    ans=d[e[0]][0]
    for i in e:
        ans=min(ans,d[i][0])
    print(ans)

Solution (Python):
import itertools

def get_target_list(source):
    targets = []
    for size in range(1, len(source) + 1):
        for x in itertools.combinations(source, size):
            targets.append(x)
    return targets

paramN, paramM, paramX = list(map(lambda x: int(x), input().split(' ')))
targets = get_target_list([list(map(lambda x: int(x), input().split(' '))) for i in range(paramN)])

price_sum = 10000000000
for books in targets:
    ps = 0
    tmp = [0 for i in range(paramM)]
    for book in books:
        ps += book[0]
        for i1, x in enumerate(book[1:]):
            tmp[i1] += x
    if len(list(filter(lambda y: y < paramX, tmp))) == 0:
        price_sum = min(price_sum, ps)

if price_sum == 10000000000:
    print(-1)
else:
    print(price_sum)

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

book = [[None]*(m+1)]*n

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

min_ans = float('inf')
for i in range(2 ** n):
    ans = 0
    rikai = [0]*m
    cost = 0

    for j in range(n):
        if((i >> j) & 1):
            p = book[j]
            for t in range(1,m+1):
                rikai[t-1] += p[t]
            cost += p[0]

    for j in range(m):
        if rikai[j] < x:
            ans = 1

    if ans == 0:
        min_ans = min(min_ans, cost)

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

Solution (Python):
from collections import defaultdict
import itertools
d = defaultdict(int)

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

for i in range(N):
    for j in range(1, M + 1):
        d[j] += L[i][j]

for i in range(M):
    if (d[i + 1] < X):
        print('-1')
        exit()

n = []
for i in range(N):
    n.append(i)

p = []
for i in range(1, N + 1):
    p.append(itertools.combinations(n, i))

ans = []
for v in p:
    for i in v:
        d2 = defaultdict(int)
        for j in range(len(i)):
            for k in range(0, M + 1):
                if (k == 0):
                    d2[0] += L[i[j]][0]
                else:
                    d2[k] += L[i[j]][k]
        count = 0

        for p, q in d2.items():
            if(p == 0):
                continue
            else:
                if(q >= X):
                    count += 1

        if (count == len(d2) - 1):
            ans.append(d2[0])

print(min(ans))

Solution (Python):

n,m,x=map(int,input().split())
lst=[]
skl=[0]*m

money=0
moneylst=[]
flag=0
for i in range(n):
    lst.append(list(map(int,input().split())))
for i in range(2**n):
    s=bin(i)[2:].zfill(n)
    sindx=0
    skl=[0]*m
    money=0
    for j in s:
        j=int(j)
        if j==1:
            
            for k in range(m):
                skl[k]+=lst[sindx][k+1]
            money+=lst[sindx][0]
            

            if all(p>=x for p in skl):
                flag=1
                moneylst.append(money)
        sindx+=1

if flag==1:
    print(min(moneylst))
else:
    print('-1')

Solution (Python):
import itertools

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

for a in range(1, N + 1):
  for c in itertools.combinations(CA, a):
    C.append(list(c))

p = float('inf')

for c in C:
  tp = float('inf')
  t = [0] * (M + 1)
  for con in c:
    for i in range(M + 1):
      t[i] += con[i]
      flg = True
    for i in range(1, M + 1):
      if t[i] < X: flg = False
    if flg: p = min(p, t[0])
      
if p == float('inf'):
  print(-1)
else:
  print(p)

Solution (Python):
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

MOD = 10**9 + 7
INF = float('inf')

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

C = [0]*N
A = [[0 for i in range(M)]for j in range(N)]

idxs = [i for i in range(N)]

ptn = []

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


for i in range(1 << len(idxs)):
    output = []
    for j in range(len(idxs)):
        if ((i >> j) & 1) == 1:
            output.append(idxs[j])
    ptn.append(output)

ans = -1
mans = 10000000000000

for p in ptn:
    cnt = [0]*M
    for i in p:
        for j in range(M):
            cnt[j] += A[i][j]

        if min(cnt) >= X:
            tmpans = 0
            for k in p:
                tmpans += C[k]
            if tmpans < mans:
                ans = p
                mans = tmpans

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

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    n,m,x=map(int,input().split())
    C=[0]*n
    A=[0]*n
    for i in range(n):
        c,*a=map(int,input().split())
        C[i]=c
        A[i]=a
    ans=-1
    for i in range(2**n):
        flag=True
        for j in range(m):
            u=0
            for d in range(n):
                u+=A[d][j]*(i>>d&1)
            if u<x:
                flag=False
        if flag:
            price=0
            for d in range(n):
                price+=C[d]*(i>>d&1)
            if ans==-1 or ans>price:
                ans=price
    print(ans)
if __name__ == '__main__':
    main()