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
def func(ans, b_list, a_list, c_list, k, x):
    if k == 0:
        b_list = np.asarray(b_list)
        x_list = np.dot(b_list, a_list)
        if np.all(x_list >= x):
            return np.inner(c_list, b_list)
        else:
            return ans
    ans = min(ans, func(ans, b_list + [1], a_list, c_list, k - 1, x))
    ans = min(ans, func(ans, b_list + [0], a_list, c_list, k - 1, x))
    return ans
n, m, x = map(int, input().split())
c_list = [] 
a_list = []
for i in range(0, n):
    c, *a = map(int, input().split())
    c_list.append(c)
    a_list.append(a)
ans = float("inf")
c_list = np.asarray(c_list)
a_list = np.asarray(a_list)
ans = min(ans, func(ans, [1], a_list, c_list, n - 1, x))
ans = min(ans, func(ans, [0], a_list, c_list, n - 1, x))
if ans == float("inf"):
    print(-1)
else:
    print(ans)

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


for i in range(2**N):
    score = [0 for _ in range(M)]
    price = 0
    for j in range(N):
        if i & 1<<j:
            for k in range(M):
                score[k] += A[j][k]
            price += C[j]    
    if min(score) >= X:
        if min_price == -1 or min_price > price:
            min_price = price

print(min_price)

Solution (Python):
from itertools import product
from operator import add

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

p = list(product([0, 1], repeat=n))
ans = float('inf')
for i in range(len(p)):
    total = [0]*m
    money = 0
    for j in range(n):
        if p[i][j] == 1:
            total = list(map(add, total, ca[j][1:m+1]))
            money += ca[j][0]
    if len([y for y in total if y >= x]) == m:
        ans = min(ans, money)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
def main():
  n,m,x = [int(x) for x in input().split()]
  c = []
  a = []
  for i in range(n):
    tmp = [int(x) for x in input().split()]
    c.append(tmp[0])
    a.append(tmp[1:])
  
  
  
  
  def check(b):
    p = b
    y = [0]*m
    z = 0
    for i in range(n):
      if p % 2 == 1:
        
        for j in range(m):
          y[j] += a[i][j]
        z += c[i]
      p = p >> 1
    
    for j in range(m):
      if y[j] < x:
        return False, -1
    return True, z
      
  minx = None
  for b in range(2**n):
    
    flg, val = check(b)
    if flg:
      minx = val if minx is None else min(val, minx) 
  print(-1 if minx is None else minx)
main()

Solution (Python):
def dfs(i, cost, skill):
    if i == n:
        if min(skill) >= x:
            return cost
        else:
            return INF
    updated_skill = [0] * m
    updated_cost = cost + C[i]
    for j in range(m):
        updated_skill[j] = skill[j] + A[i][j]
    return min(dfs(i + 1, cost, skill), dfs(i + 1, updated_cost, updated_skill))
    
    

    
    


    


INF = float('inf')

n, m, x = map(int, input().split())
C = []
A = []









for _ in range(n):
    li = list(map(int, input().split()))
    C.append(li[0])
    A.append(li[1:])



min_cost = dfs(0, 0, [0] * m)
if min_cost == INF:
    print('-1')
else:
    print(min_cost)

Solution (Python):
n, m, x = 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:m+1])

ans = sum(C) + 1

for i in range(2**n):
    
    study = [0] * m
    price = 0
    for j in range(n):
        if i >> j & 1:
            for k in range(m):
                study[k] += A[j][k]
            price += C[j]
            
            if min(study) >= x:
                ans = min(ans, price)

if ans == sum(C) + 1:
    print(-1)
else:
    print(ans)

Solution (Python):
n, m, x = 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:m+1])

ans = sum(C) + 1

for i in range(2**n):
    
    study = [0] * m
    price = 0
    for j in range(n):
        if i >> j & 1:
            for k in range(m):
                study[k] += A[j][k]
            price += C[j]
            
            if min(study) >= x:
                ans = min(ans, price)

if ans == sum(C) + 1:
    print(-1)
else:
    print(ans)

Solution (Python):
def ha(mm,x):
    mm=[1  if i//x >=1 else 0 for i in mm]
    if sum(mm)>=len(mm):
        return 0
    else:
        return 1

def so(hr,ca,m,an):
    wk = 0
    mm = [0]*m
    for i in range(len(hr)):
        if hr[i] == 1:
            wk += ca[i][0]
            hr[i] = 1
            for j in range(m):
                mm[j] += ca[i][j+1]
        else:
            i += 1
    if ha(mm,x)==0:
        an=min(wk,an)
        return an
    return an

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

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

an += 1
han = an
hr = [0]*n
for ka in range(1,2**n):
    hr = [int(i) for i in list(format(ka, 'b').zfill(n))]
    an = so(hr,ca,m,an)
if an == han:
    print('-1')
else:
    print(an)

Solution (Python):
import sys
from collections import deque
import copy
INF = 10000000
def main():
    N, M, X = map(int, input().split())
    book = []
    ans = INF
    for i in range(N):
        info = [int(i) for i in input().split()]
        book.append(info)
    for i in range(1 << N):
        a = []
        for j in range(M + 1):
            a.append(0)    
        for j in range(N):
            if (i >> j) & 1:
                for t in range(M + 1):
                    a[t] += book[j][t]
        for j in range(1, M + 1):
            if a[j] < X:
                a[0] = INF
                break
        ans = min(ans, a[0])
    if ans >= INF:
        ans = -1
    print(ans)







if __name__ == '__main__':
    main()

Solution (Python):
n,m,x=map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
ans=float('inf')

for i in range(1,2**n):
    rikaido = [0]*m
    money=0
    for j in range(n):
        
        if i>>j&1:
            money+=ca[j][0]
            for k in range(1,m+1):
                rikaido[k-1]+=ca[j][k]
        for l in range(m):
            
            if all(rikaido[l] >= x for l in range(m)):
                ans=min(money,ans)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
import numpy as np

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

books = []
prices = []
for _ in range(n):
    a = list(map(int, input().split()))
    c = a.pop(0)
    prices.append(c)
    books.append(a)

books = np.array(books)

ans = 10 ** 7
for i in range(2 ** n):
    sel = np.zeros(m)
    price = 0

    for j in range(n):
        if (i >> j) & 1:
            sel += books[j]
            price += prices[j]
    if (sel >= x).all() and price < ans:
        ans = price

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

Solution (Python):
from itertools import product
n, m, x = map(int, input().split())
costs = []
gets = []
for i in range(n):
    cost, *argo = map(int, input().split())
    costs.append(cost)
    gets.append(argo)

    
bits_list = list(product([0,1], repeat=n))
min_cost = float('inf')
cnt = 0
for bits in bits_list:
    tmp_cost = 0
    tmp_argo = [0] * m
    for i, v in enumerate(bits):
        if v:
            tmp_cost += costs[i]
            for j, p in enumerate(gets[i]):
                tmp_argo[j] += p
                
    if all(map(lambda X:X>=x, tmp_argo)):
        min_cost = min(min_cost, tmp_cost)
        cnt = 1
if cnt:
    print(min_cost)
else:
    print(-1)

Solution (Python):
n,m,x = map(int,input().split())
B=[list(map(int,input().split())) for i in range(n)]
ANS = 1 << 100
for i in range(1 << n):
    SCORE = [0] * m
    MONEY = 0
    for j in range(n):
        if (1 << j) & i != 0:
            MONEY+=B[j][0]
            for k in range(m):
                SCORE[k] += B[j][k+1]
    if min(SCORE) >= x:
        ANS = min(ANS,MONEY)
if ANS == 1 << 100:
    print(-1)
else:
    print(ANS)

Solution (Python):

n,m,k=map(int,input().split())
A=[]
for i in range(n):
    row=list(map(int,input().split()))
    A.append(row)
mn=10**9
for i in range(int(2**n)):
    x=bin(i)[2:]
    x=("0"*(n-len(x)))+x
    curr=[0 for ptr in range(m)]
    s=0
    for j in range(n):
        if(x[j]=="1"):
            s+=A[j][0]
            curr=[curr[ptr]+A[j][ptr+1] for ptr in range(m) ]

    curr=[curr[ptr]>=k for ptr in range(m)]
    curr=list(set(curr))
    if(curr==[True]):
        if(s<mn):
            mn=s
if(mn==10**9):
    print(-1)
else:
    print(mn)

Solution (Python):
import numpy as np
from numpy import array


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

a = array(a)

c_min = 0
flag = False

for i in range(1, 2 ** n ):
    b = np.zeros(m+1)

    for k in range(n):
        if ((i >> k) & 1):
            b += a[k]
    
    if np.all(b[1:] >= x):
        if flag == False:
            c_min = b[0]
            flag = True
        else:
            c_min = min(c_min, b[0])
        

c_min = int(c_min)

if flag == False:
    c_min = -1

print(c_min)

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


for i in range(2**n):
    flag=0
    bought_text=np.array([0 for j in range(m+1)])
    for j in range(n):
        
        if((i>>j)&1):
            bought_text+=text[j]
    for k in range(m):
        if bought_text[k+1]<x:
            flag=1
            break
    if flag==0:
        cost.append(bought_text[0])
print(min(cost) if cost else "-1")

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

INF = 9999999999
ans = INF
for i in range(2 ** N):
    price = []
    rikaido = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            price.append(C[j])
            for k in range(M):
                rikaido[k] += A[j][k]
    for l in range(M):
        if rikaido[l] < X:
            break
    else:
        ans = min(ans, sum(price))

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

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

    result = 10 ** 5 * 12 + 1
    for i in range(2 ** N):
        b = ('0' * N + format(i, 'b'))[-N:]
        r = [0] * M
        sub_res = 0
        for j, s in enumerate(b):
            if int(s) == 1:
                sub_res += C[j]
                for k in range(M):
                    r[k] += A[j][k]
        if all([rx >= X for rx in r]):
            result = min(result, sub_res)
    if result != 10 ** 5 * 12 + 1:
        print(result)
    else:
        print(-1)


if __name__ == '__main__':
    solve()

Solution (Python):
inf = 10**9
n, m, x = map(int, input().split())
a = [0] * n
c = [0] * n
y = [0] * n
for i in range(n):
    data = list(map(int, input().split()))
    c[i] = data[0]
    a[i] = data[1:]
ans = inf
for i in range(2**n):
    money = 0
    know = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            money += c[j]
            for k in range(m):
                know[k] += a[j][k]
    for z in know:
        if z < x:
            break
    else:
        ans = min(ans, money)

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

Solution (Python):
inf = 10**9
n, m, x = map(int, input().split())
a = [0] * n
c = [0] * n
y = [0] * n
for i in range(n):
    data = list(map(int, input().split()))
    c[i] = data[0]
    a[i] = data[1:]
ans = inf
for i in range(2**n):
    lis = [0]*n
    money = 0
    know = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            money += c[j]
            for l in range(m):
                know[l] += a[j][l]
    for z in know:
        if z < x:
            break
    else:
        ans = min(ans, money)

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

Solution (Python):
def main():
    N,M,X=map(int, input().split())
    A=[list(map(int, input().split())) for _ in range(N)]
    ans=10**10
    for i in range(2**N):
        b=i+2**N
        c=0
        l=[0]*M
        ok=True
        for j in range(N):
            if b>>j&1 == 1:
                c+=A[j][0]
                for k in range(M):
                    l[k]+=A[j][k+1]
        for x in l:
            if x < X: ok = False 
        if ok:
            ans = min(ans, c)
    if ans==10**10: print('-1')
    else: print(ans)

if __name__=='__main__':
    main()

Solution (Python):
def main():
    N,M,X=map(int, input().split())
    A=[list(map(int, input().split())) for _ in range(N)]
    ans=10**10
    for i in range(2**N):
        b=i+2**N
        c=0
        l=[0]*M
        ok=True
        for j in range(N):
            if b>>j&1 == 1:
                c+=A[j][0]
                for k in range(M):
                    l[k]+=A[j][k+1]
        for x in l:
            if x < X: ok = False 
        if ok:
            ans = min(ans, c)
    if ans==10**10: print('-1')
    else: print(ans)

if __name__=='__main__':
    main()

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




cost=1200100

for i in range(2**N-1):
    price=0
    num=format(i+1,'0{}b'.format(N))
    arg=[0]*M 
    for e in range(N):
        if  num[N-1-e]=="1":
            for u in range(M):
                arg[u]+=List[e][u+1]
            price+=List[e][0]  
    b=1
    
    
    for t in range(M):
        if  not arg[t]>=X:
            b=2
        
    if price<=cost and b==1:
        cost=price
if cost==1200100:
    print("-1")
else:
    print(cost)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, m, x = map(int, readline().split())
    bookcosts = [] 
    data = [] 
    for _ in range(n):
        c, *d = map(int, readline().split())
        bookcosts.append(c)
        data.append([i for i in d])
    INF = int(1e9)
    
    ans = INF
    for i in range(1<<n):
        cost = 0
        score = [0 for _ in range(m)]
        for j in range(n):
            if (i>>j) & 1:
                
                
                cost += bookcosts[j]
                
                for k in range(m):
                    score[k] += data[j][k]
        
        f = True
        for j in range(m):
            if score[j] >= x:
                pass
            else:
                f = False
        
        if f:
            ans = min(cost, ans)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
from collections import deque 
INF = int(1e9)
ans = INF
def main():
    N, M, X = map(int, readline().split())
    costs = []
    score = []
    for _ in range(N):
        c, *d = map(int, readline().split())
        costs.append(c)
        score.append([i for i in d])
    dq = deque()
    def dfs():
        global ans
        if len(dq) == N:
            cost = 0
            sumScore = [0 for _ in range(M)]
            for i in range(N):
                if dq[i]:
                    cost += costs[i]
                    for j in range(M):
                        sumScore[j] += score[i][j]
            flag = True 
            for i in range(M):
                if sumScore[i] < X: 
                    flag = False

            if flag:
                ans = min(ans, cost)
                return 
            return 
        for i in range(2): 
            dq.append(i)
            dfs()
            dq.pop()

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
from collections import deque 
INF = int(1e9)
ans = INF
def main():
    N, M, X = map(int, readline().split())
    costs = []
    score = []
    for _ in range(N):
        c, *d = map(int, readline().split())
        costs.append(c)
        score.append([i for i in d])
    dq = deque()
    def dfs():
        global ans
        if len(dq) == N:
            cost = 0
            sumScore = [0 for _ in range(M)]
            for i in range(N):
                if dq[i]:
                    cost += costs[i]
                    for j in range(M):
                        sumScore[j] += score[i][j]
            flag = True 
            for i in range(M):
                if sumScore[i] < X: 
                    flag = False

            if flag:
                ans = min(ans, cost)
                return 
            return 
        for i in range(2): 
            dq.append(i)
            dfs()
            dq.pop()

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

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

C = [row[0] for row in CA]
A = [row[1:] for row in CA]

def solve(N, M, X, C, A):
    result = -1
    for n in range(2**N):
        xs = [0] * M
        r = 0
        for i in range(N):
            if ((1 << i) & n):
                r += C[i]
                for j in range(M):
                    xs[j] += A[i][j]
        if all(X <= xs[j] for j in range(M)):
            if result == -1 or r < result:
                result = r
    return result

print(solve(N, M, X, C, A))

Solution (Python):
N, M, X = map(int, input().split())
C = []
A = []
for _ in range(N):
    s = list(map(int, input().split()))
    C.append(s[0])
    A.append(s[1:])
ans = float('INF')
for i in range(0, 1 << N):
    scores = [0] * M
    count = 0
    for j in range(N):
        if (i >> j) & 1:
            for s in range(M):
                scores[s] += A[j][s]
            count += C[j]
    if min(scores) < X:
        continue
    else:
        ans = min(ans, count)

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

Solution (Python):
def makeComb(num):
    if num == n:
        totalM = [0] * m
        totalC = 0
        for i in range(n):
            if s[i] == 1:
                for j in range(m):
                    totalM[j] += ca[i][j+1]
                totalC += ca[i][0]
        for i in range(m):
            if totalM[i] < x:
                return
        global ans
        ans = min(ans, totalC)
        return

    makeComb(num+1)
    s[num] = 1
    makeComb(num+1)
    s[num] = 0

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

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

INF = 1001001001
ans = INF

s = [0] * n
makeComb(0)

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

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

minCost = 12 * (10**5)
count = 0

for i in range(2**N):
    total = 0
    flag = 1
    B = [0] * M
    for j in range(N):
        if ((i >> j) & 1):
            total = total + a[j][0]
            for k in range(M):
                B[k] = B[k] + a[j][k + 1]
    for l in range(M):
        if B[l] < X:
            flag = 0
    if flag:
        minCost = min(minCost,total)
    count = count + flag

if count:
    print(minCost)
else:
    print("-1")

Solution (Python):
from itertools import product

N, M, X = map(int, input().split())
INF = 10**15
ans = INF
cl, al  = [], []
for _ in range(N):
    c, *a, = map(int, input().split())
    cl.append(c)
    al.append(a)

for i in product(range(2), repeat=N):
    b = [0]*M
    tc = 0
    for j, k in enumerate(i):
        if k:
            tc += cl[j]
            for o, p in enumerate(al[j]):
                b[o] += p
    if all(map(lambda x:x>=X, b)):
        ans = min(ans, tc)
print(ans if ans!=INF else -1)

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

x = [ [0 for i in range(m)] for j in range(n)]

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



ans = 1e9
for mask in range(2**n):
    tans = 0
    skill = [0 for i in range(m)]
    for i in range(n):
        if (mask >> i) & 1 > 0:
            tans += c[i]
            for j in range(m):
                skill[j] += x[i][j]
    suc = True
    for i in range(m):
        if skill[i] < X:
            suc = False
            break

    if suc:
        ans = min(ans, tans)

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

Solution (Python):
blist = []
def createBitline(N, p, bl):
	if(N == p and len(bl) == N):
		blist.append(bl)
	else:
		createBitline(N, p + 1, bl + "0")
		createBitline(N, p + 1, bl + "1")
 
def checkClear(X, list):
	for i in range(1, len(list)):
		if int(list[i]) < X:
			return False
	return True
 
listCA = []
N,M,X = map(int, input().split())
for i in range(N):
	listCA.append(input().split())
createBitline(N, 0, "")
cost = []
for x in range(len(blist)):
	sumCA = [0] * (M + 1)
	for i in range(N):
		if blist[x][i] == "1":
			for j in range(len(listCA[i])):
				sumCA[j] += int(listCA[i][j])
	if checkClear(X, sumCA):
		cost.append(sumCA[0])
if cost:
	print(min(cost))
else:
	print('-1')

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    import itertools
    
    N,M,X=MI()
    C=[0]*N
    A=[]
    for i in range(N):
        ca=LI()
        C[i]=ca[0]
        A.append(ca[1:])
        
    ans=10**10
    for ite in itertools.product([0,1], repeat=N):
        score=[0]*M
        temp=0
        for i in range(N):
            if ite[i]:
                temp+=C[i]
                for j in range(M):
                    score[j]+=A[i][j]
        if min(score)>=X:
            ans=min(ans,temp)
            
    if ans==10**10:
        ans=-1
    print(ans)
                
            
       

main()

Solution (Python):
n,m,x=map(int,input().split())
A=[list(map(int,input().split()))for a in range(n)]
mi=[10**7]

for i in range(2**n):
  und=[0]*m
  money=0
  for j in range(n):
    if (i >> j)&1:
      money+=A[j][0]
      for u in range(m):
        und[u]+=A[j][u+1]
  if all(und[s]>=x for s in range(m)):    
    mi.append(money)
   
print(min(mi) if min(mi)!=10**7 else -1)

Solution (Python):
import copy

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

li = [[0 for i in range(M+1)] for j in range(N)]

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

sumLiA = [0 for i in range(M+1)]
sumLi = copy.deepcopy(sumLiA)
costLi = []
flag = 1

for pat in range(2**N):
  pat = format(pat, '012b')
  for bookNum in range(N):
    if pat[-bookNum-1] == '1':
      for i in range(M+1):
        sumLi[i] += li[-bookNum-1][i]
  for liN in range(1, M+1):
    if sumLi[liN] < X:
      flag = 0
      break
  if flag == 1:
    costLi.append(sumLi[0])
  flag = 1
  sumLi = copy.deepcopy(sumLiA) 

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

Solution (Python):
import sys
import numpy as np
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N,M,X = map(int, readline().split())
data = np.array(read().split(), np.int64)
data = data.reshape(N,-1)
C = data[:,0]
A = data[:,1:]
 
cost = np.zeros(1<<N, np.int64)
ability = np.zeros((1<<N, M), np.int64)
 
for i in range(N):
  cost[1<<i:1<<(i+1)] = cost[:1<<i] + C[i]
  ability[1<<i:1<<(i+1)] = ability[:1<<i] + A[i]
  
ok = np.all(ability >= X, axis=1)
 
x = cost[ok]
answer = -1 if len(x) == 0 else x.min()
print(answer)

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

cost = []

for i in range(2 ** N):
    skill = [0] * M
    total = 0
    for j in range(N):
        if (i >> j) & 1:
            for k in range(M):
                skill[k] += C[j][k + 1]
            total += C[j][0]
    flg = 1
    for sk in skill:
        if sk < X:
            flg = 0
    if flg == 1:
        cost.append(total)

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

Solution (Python):
if __name__ == "__main__":
    n, m, x = map(int, input().split())
    ca = []
    for _ in range(n):
        tmp = list(map(int, input().split()))
        ca.append(tmp)
    ans = float('inf')
    for mask in range(1 << n):
        cost = 0
        algo = [0] * m

        for i in range(n):
            if 1 & (mask >> i):
                cost += ca[i][0]
                for j in range(1, m + 1):
                    algo[j - 1] += ca[i][j]
        ok = True
        for i in range(m):
            if algo[i] < x:
                ok = False
                break
        if ok:
            ans = min(ans, cost)
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)

Solution (Python):
import numpy as np
import itertools
n, m, x = list(map(int, input().split()))
c = np.array([list(map(int, input().split())) for _ in range(n)])
pre = np.arange(n)
l = []
rem = []
ans = 0
for i in pre + 1:
    for j in itertools.combinations(pre, i):
        l.append(list(j))
for i in range(1, m + 1):
    for j, k in enumerate(l):
        ca = 0
        for ii in k:
            ca += c[ii, i]
        if ca < x:
            rem.insert(0, j)
        else:
            pass
    if len(rem) > 0:
        for j in rem:
            l.pop(j)
        rem = []
    if len(l) == 0:
        print(-1)
        break
else:
    for i in l:
        ca = 0
        for j in i:
            ca += c[j, 0]
        if ans == 0:
            ans = ca
        else:
            ans = min(ans, ca)
    print(ans)

Solution (Python):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

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

def inpl_str(): return list(sys.stdin.readline().split())

N, M, X = inpl()
books = list(list(map(int, input().split())) for _ in range(N))
ans = INF
for i in range(2**N):
    c = 0
    skill = [0]*M
    for j in range(N):
        if 1 << (j) & i:
            c += books[j][0]
            for k in range(M):
                skill[k] += books[j][k+1]
    if min(skill) >= X:
        ans = min(ans, c)
if ans == INF:
    print(-1)
else:
    print(ans)

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]
def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)

def len_check(k,n):
    if len(k) == n:
        return k
    else:
        for _ in range(n-len(k)):
            k = '0'+k
        return k

N,M,X = inputlist()
li = [0]*N
cost = 10**9
for i in range(N):
    li[i] = inputlist()
for k in range(2**N):
    ans = [0]*M
    k = len_check(base10to(k,2),N)
    lis = []
    tmp = 0
    count = 0
    for i in range(N):
        if k[i] == '1':
            lis.append(li[i])
    n = len(lis)
    for i in range(n):
        tmp += lis[i][0]
        alg = lis[i][1:]
        for j in range(M):
            ans[j] += alg[j]
    for i in range(M):
        if ans[i] >= X:
            count+=1
    if count == M:
        cost = min(cost,tmp)

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

Solution (Python):
n,m,x = map(int,input().split())
a = [0]*n
for i in range(n):
    a[i] = list(map(int,input().split()))
ans = 10**7
for i in range(2**n):
    count = 0
    sw = [0]*m
    for j in range(n):
        if (i>>j)&1:
            count += a[j][0]
            for k in range(m):
                sw[k] += a[j][k+1]
    q = 1
    for L in range(m):
        if sw[L] < x:
            q = 0
            break
    if q == 1:
        ans = min(ans,count)
if ans == 10**7:
    print(-1)
else:
    print(ans)

Solution (Python):
inf = 10**9
n, m, x = map(int, input().split())
a = [0] * n
c = [0] * n
y = [0] * n
for i in range(n):
    data = list(map(int, input().split()))
    c[i] = data[0]
    a[i] = data[1:]
ans = inf
for i in range(2**n):
    lis = [0]*n
    k = i
    money = 0
    know = [0] * m
    for j in range(n):
        if (k >> j) & 1:
            money += c[j]
            for l in range(m):
                know[l] += a[j][l]
    for z in know:
        if z < x:
            break
    else:
        ans = min(ans, money)

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

Solution (Python):
import numpy as np
n, m, x = map(int, input().split())
Book = [list(map(int, input().split())) for _ in range(n)]
cost = [0 for _ in range(2**n)]
skill = [np.zeros(m) for _ in range(2**n)]
cost2 = []
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1:
            cost[i] += Book[j][0]
            skill[i] += np.array(Book[j])[1:m+1]
    if np.min(skill[i]) >= x:
        cost2.append(cost[i])
if cost2:
    print(min(cost2))
else:
    print(-1)

Solution (Python):
import numpy as np
n, m, x = map(int, input().split())
Book = [list(map(int, input().split())) for _ in range(n)]
cost = [0 for _ in range(2**n)]
skill = [np.zeros(m) for _ in range(2**n)]
cost2 = []
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1:
            cost[i] += Book[j][0]
            skill[i] += np.array(Book[j])[1:m+1]
    if np.min(skill[i]) >= x:
        cost2.append(cost[i])
if len(cost2) > 0:
    print(min(cost2))
else:
    print(-1)