Problem:
 Score : 300 points    Problem Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0 .  Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i -th book ( 1\leq i\leq N ) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j -th algorithm will increase by A_{i,j} for each j ( 1\leq j\leq M ).
There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.      Constraints  All values in input are integers.  1\leq N, M\leq 12  1\leq X\leq 10^5  1\leq C_i \leq 10^5  0\leq A_{i, j} \leq 10^5         Input Input is given from Standard Input in the following format:  N  M  X  C_1  A_{1,1}  A_{1,2}  \cdots  A_{1,M}  C_2  A_{2,1}  A_{2,2}  \cdots  A_{2,M}  \vdots  C_N  A_{N,1}  A_{N,2}  \cdots  A_{N,M}       Output If the objective is not achievable, print -1 ; otherwise, print the minimum amount of money needed to achieve it.        Sample Input 1 3 3 10
60 2 2 4
70 8 7 9
50 2 3 9      Sample Output 1 120  Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.       Sample Input 2 3 3 10
100 3 1 4
100 1 5 9
100 2 6 5      Sample Output 2 -1  Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.       Sample Input 3 8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2      Sample Output 3 1067

Solution (Python):

N, M, X = map(int, input().split())
A = []
c = []

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

inf = 10**9
ans = inf

for s in range(1 << N):
    un = [0]*M
    price = 0
    for i in range(N):
        if (s >> i) % 2 == 0:
            continue
        price += c[i]
        for j in range(M):
            un[j] += A[i][j]

    ok = True
    for j in range(M):
        if un[j] < X:
            ok = False
    if ok:
        ans = min(ans, price)

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

print(ans)

Solution (Python):
from sys import stdin
import numpy as np

def bit_search(a, n, m, x):
    min_price = np.inf
    for i in range(2 ** n):
        price = 0
        skill = np.zeros((n, m))
        for j in range(n):
            if (i >> j) & 1:
                price += a[j][0]
                skill[j] = a[j][1:]
        skill_sum = np.sum(skill, axis=0)\
                        if skill.shape[0] > 1 else skill
        if not (skill_sum >= x).all() or price > min_price: continue
        min_price = price
    return  min_price

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    min_price = bit_search(a, n, m, x)
    return print('-1' if np.isinf(min_price) else  min_price)

if __name__ == '__main__':
    main()

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

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



ans = 10 ** 8

for i in range(1 << n):
    cost = 0
    check = True
    d = [0 for i in range(m)]
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for i2 in range(m):
                d[i2] += a[j][i2]
            
    for k in range(m):
        if d[k] < x:
            check = False
    if check:
        ans = min(ans, cost)
    
    
if ans == 10 ** 8:
    print(-1)
else:
    print(ans)

Solution (Python):
from sys import stdin
import numpy as np

def bit_search(a, n, m, x):
    res = []
    for i in range(2 ** n):
        price = 0
        skill = np.zeros((n, m))
        for j in range(n):
            if (i >> j) & 1:
                price += a[j][0]
                skill[j] = a[j][1:]
        skill_sum = np.sum(skill, axis=0)\
                        if skill.shape[0] > 1 else skill
        if (skill_sum >= x).all(): res.append(price)
    return res

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = bit_search(a, n, m, x)
    print('-1' if not res else min(res))
    return

if __name__ == '__main__':
    main()

Solution (Python):
N, M, X = map(int, input().split())
C, A = [], []

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

ans = float('inf')
for j in range(1<<N):
    curr = 0
    score = [0] * M
    for k in range(N):
        if 1<<k & j :
            curr += C[k]
            for m in range(M):
                score[m] += A[k][m]
                
    if min(score) >= X:
        ans = min(curr, ans)

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

Solution (Python):
from itertools import product

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

INIT = 10**10
ans = INIT
pat = list(product([0, 1], repeat=n))

for p in pat:
    a_val = [0] * m
    c_yen = 0

    for i in range(n):
        if p[i] == 1:
            c_yen += c[i]
            for j in range(m):
                a_val[j] += a[i][j]

    flag = True
    for i in range(m):
        if a_val[i] < x:
            flag = False
            break
    if flag:
        ans = min(ans, c_yen)

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

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

for i in range(n):
    l = [int(_) for _ in input().split()]
    c[i]=l[0]
    for j in range(m):
        a[i][j] = l[j+1]

inf=float('inf')
ans=inf
for i in range(2 ** n):
    cost = 0
    d=[0]*m
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for k in range(m):
                d[k] += a[j][k]

    ok = True
    for y in range(m):
        if d[y] < x:
            ok = False
    if ok:
        ans = min(ans, cost)
if ans == inf:
    print(-1)
else:
    print(ans)

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

def F(p):
    cost = 0
    rikais = [0] * M
    for i in range(N):
        if (p >> i) & 1:
            cost += C[i]
            for t in range(M):
                rikais[t] += A[i][t]
    return rikais, cost

ans = float("inf")
for p in range(2 ** N):
    rikais, cost = F(p)
    all_clear = True
    for r in rikais:
        if r >= X:
            continue
        if r < X:
            all_clear = False
    if all_clear:
        ans = min(cost, ans)
if ans == float("inf"):
    print(-1)
else:
    print(ans)

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

ans = float("inf")
for i in range(2**n):
    l = [0] * m
    c = 0
    for j ,d in enumerate(format(i, "b").zfill(n)):
        f = 0
        if d == "1":
            c += ca[j][0]
            for k in range(1, m+1):
                l[k-1] += ca[j][k]
            
    for li in l:
        if li < x:
            f = 1
            break
    if f:
        continue
    ans = min(ans, c)

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

Solution (Python):
import numpy as np

n, m, x = map(int, input().split())
c = []
a = np.zeros((n, m))
for i in range(n):
    ll = list(map(int, input().split()))
    c.append(ll[0])
    a[i] += np.array(ll[1:])
    

ans = float("INF")

s = []

def dfs(s):
    global ans
    if len(s) == n:
        r = np.zeros(m)
        ra = 0
        for j, k in enumerate(s):
            if k == 0:
                continue
            r += np.array(a[j])
            ra += c[j]
        if min(r) >= x:
            ans = min(ans, ra)
        return
    b = s.copy()
    nb = s.copy()
    b.append(0)
    nb.append(1)
    dfs(b)
    dfs(nb)

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

Solution (Python):
import numpy as np

n, m, x = map(int, input().split())
c = []
a = np.zeros((n, m))
for i in range(n):
    ll = list(map(int, input().split()))
    c.append(ll[0])
    a[i] += np.array(ll[1:])
    

ans = float("INF")

s = []

def dfs(s):
    global ans
    if len(s) == n:
        r = np.zeros(m)
        ra = 0
        for j, k in enumerate(s):
            if k == 0:
                continue
            r += np.array(a[j])
            ra += c[j]
        if min(r) >= x:
            ans = min(ans, ra)
        return
    b = s.copy()
    nb = s.copy()
    b.append(0)
    nb.append(1)
    dfs(b)
    dfs(nb)

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

Solution (Python):
from itertools import product
def main():
    n, m, x = map(int, input().split())
    books = []
    for _ in range(n):
        books.append(tuple(map(int, input().split())))

    books_set_all = []
    books_pattern = product((0, 1), repeat=n)
    for each_pattern in books_pattern:
        books_set = [0] * (m + 1)
        for i1 in range(n):
            if each_pattern[i1] == 1:
                for i2 in range(m + 1):
                    books_set[i2] += books[i1][i2]
        books_set_all.append(books_set)
    price_all = []
    for ebs in books_set_all:
        price = ebs[0]
        ebs[0] = x
        if len([j for j in ebs if j >= x]) == m + 1:
            price_all.append(price)
    if len(price_all) > 0:
        print(min(price_all))
    else:
        print(-1)

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 = 10**10
for i in range(2 ** n):
         tmp = [0] * (m+1)
         price = 0
         for j in range(n):
                  if (( i >> j ) & 1 ) == 1:
                           for k in range(m+1):
                                    tmp[k] += ca[j][k]
         for l in range(1,m+1):
                  if tmp[l] < x:
                           break
         else:
                  if ans > tmp[0]:
                           ans = tmp[0]
if ans == 10**10:
         print(-1)
else:
         print(ans)

Solution (Python):
n,m,x = map(int,input().split())
cc = []
aa = []
for _ in range(n):
    c,*a = [int(i) for i in input().split()]
    cc.append(c)
    aa.append(a)
ans = 10**18
for i in range(2**n):
    ri = [0]*m
    co = 0
    for j in range(n):
        if (i>>j) & 1 == 1:
            co += cc[j]
            for k in range(m):
                ri[k] += aa[j][k]
                
    for j in ri:
        if j < x:
            break
    else:
        ans = min(ans,co)
        
if ans == 10**18:
    print(-1)
else:
    print(ans)

Solution (Python):


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

    minCost = 10**20

    for i in range(1, 2**n):
        
        inBit = ''.join(['{:0', str(n), 'b}']).format(i)[::-1]
        knowledge = [0 for _ in range(m)]
        cost = 0

        for bit in range(len(inBit)):
            if inBit[bit] == '1':
                cost += List[bit][0]
                for j in range(m):
                    knowledge[j] += List[bit][j+1]
        
        requirement = [a >= b for (a, b) in zip(knowledge, [x for _ in range(m)])]
        
        if False not in requirement and cost < minCost:
            minCost = cost
    
    if minCost == 10**20:
        print(-1)
    else:
        print(minCost)

if __name__ == '__main__':
    main()

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

a_list = list()
c_list = list()

INF = 1001001001

for i in range(0, n):
    tmp = list(map(int, input().split()))
    c = tmp.pop(0)
    c_list.append(c)
    a_list.append(tmp)

ans = INF

for s in range(0, 1 << n):
    cost = 0
    d = [0]*m
    for i in range(0, n):
        if s >> i & 1:
            cost += c_list[i]
            for j in range(0, m):
                d[j] += a_list[i][j]
    ok = True
    for j in range(0, m):
        if d[j] < x:
            ok = False
    if ok:
        ans = min(ans, cost)

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

Solution (Python):
def main():
    n, m, x = map(int, input().split())
    books = []
    for _ in range(n):
        books.append(tuple(map(int, input().split())))

    books_set_all = []
    for bit in range(1<<n):
        books_set = [0] * (m + 1)
        for i in range(n):
            mask = 1 << i
            if bit & mask:
                for i2 in range(m + 1):
                    books_set[i2] += books[i][i2]
        books_set_all.append(books_set)
    price_all = []
    for ebs in books_set_all:
        price = ebs[0]
        ebs[0] = x
        if len([j for j in ebs if j >= x]) == m + 1:
            price_all.append(price)
    if len(price_all) > 0:
        print(min(price_all))
    else:
        print(-1)



if __name__ == '__main__':
    main()

Solution (Python):
import itertools
n,m,x = map(int,input().split())
c_li = []
a_li = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    c_li.append(tmp[0])
    a_li.append(tmp[1:])
kumi = list(itertools.product([0,1], repeat=n))
ans_li = []
for each_kumi in kumi:
    each_li = [0]*m
    score = 0
    for i,k in enumerate(each_kumi):
        if k == 1:
            score += c_li[i]
            for j,kk in enumerate(a_li[i]):
                each_li[j] += kk
    flag = True
    for ea in each_li:
        if ea<x:
            flag = False
    if flag:
        ans_li.append(score)
if len(ans_li)==0:
    print(-1)
else:
    print(min(ans_li))

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

c=[]
a=[]

INF=1001001001
ans=INF

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

for i in range(1<<n):
  cost=0
  skill=[0 for _ in range(m)]
  for j in range(n):
    if (i>>j)&1==1:
      
      cost+=c[j]
      for k in range(m):
        skill[k]+=a[j][k]
  
  flag=True
  for j in range(m):
    if skill[j]<x:
      flag=False
      break
  if flag:
    ans=min(ans,cost)
if ans==INF:
  ans=-1
print(ans)

Solution (Python):
from sys import stdin
import numpy as np

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = []
    for i in range(2 ** n):
        price = 0
        skill = []

        for j in range(1 << n):
            if ((i >> j) & 1) == 1:
                price += a[j][0]
                skill.append(a[j][1:])
        np_skill = np.array(skill)
        skill_sum = np.sum(np_skill, axis=0)\
                        if np_skill.shape[0] > 1 else np_skill

        if skill_sum.size != 0 and (skill_sum >= x).all():
            res.append(price)

    if not res: return print('-1')

    return print(min(res))

if __name__ == '__main__':
    main()

Solution (Python):
N, M, X = map(int, input().split())
C = [0] * N
A = [[0 for _ in range(M)] for _ in range(N)]
for i in range(N):
  A[i] = list(map(int, input().split()))
  C[i] = A[i][0]
  A[i] = A[i][1:]
ans = sum(C) + 1
Y = [0] * M
for p in range(2 ** N):
  for i in range(M):
    Y[i] = 0
  cnt = 0
  _p = p
  for i, c in enumerate(C):
    if _p % 2 == 1:
      cnt += c
      for j, a in enumerate(A[i]):
        Y[j] += a
    _p //= 2
  ans = min(ans, cnt) if min(Y) >= X else ans
print(ans if ans <= sum(C) else -1)

Solution (Python):
from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
import sys
sys.setrecursionlimit(1000000)
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def o():
    return int(input())
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')
MOD =    1000000007
MAX=float('inf')
MIN=-float('inf')
p=input

n,m,x=io()
cost=[0]*n
a=[0]*n
skill=[0]*m

for i in range(n):
    t=op()
    cost[i]=t[0]
    a[i]=t[1:]
ans=MAX
for i in range(1<<n):
    c=0
    skill=[0]*m
    for j in range(n):
        if (i>>j)&1:
            c+=cost[j]
            for k in range(m):
                skill[k]+=a[j][k]
    if min(skill) >= x:
        ans=min(ans,c)
if ans==MAX:print(-1)
else:print(ans)

Solution (Python):

import sys
from itertools import combinations

N,M,X = map(int,input().split())
CA = [list(map(int,input().split())) for _ in range(N)]
A=[0]*(M+1)

ans=0

for i in range(N):
    ans+=CA[i][0]
    for j in range(1,M+1):
        A[j]+=CA[i][j]


for i in range(1,M+1):
    if A[i] <X:
        print(-1)
        sys.exit()


for i in range(1,N+1):
    for e in combinations(range(N),i):
        c = 0
        A = [0]*M
        for f in e:
            c += CA[f][0]
            for j in range(M):
                A[j] += CA[f][j+1]
        if min(A) >= X:
            ans = min(ans,c)
        
else:
    print(ans)

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

C = []
A = []

for _ in range(N):
    CA = [int(x) for x in input().split()]
    C.append(CA[0])
    A.append(CA[1:])

INF = 99999999999999999999999
minC = INF

for i in range(1<<N):
    tmpC = 0
    tmpA = [0] * M
    for j in range(N):
        if i & (1 << j):
            tmpC += C[j]
            for k in range(M):
                tmpA[k] += A[j][k]

    if min(tmpA) >= X:
        minC = min(tmpC, minC)

print(minC if minC!=INF else -1)

Solution (Python):
import sys
from itertools import product
import numpy as np

n, m, x = map(int, input().split())
a = np.array([list(map(int, input().split())) for _ in range(n)], dtype = np.int32)
ans = sys.maxsize
for bit in product((False, True), repeat = n):
    row_sum = np.sum(a[np.where(bit)], axis = 0)
    if m == np.count_nonzero(row_sum[1:] >= x):
        ans = min(ans, row_sum[0])
print(-1 if ans == sys.maxsize else ans)

Solution (Python):
def main():
    N, M, X, *CA = map(int, open(0).read().split())
    C = [0]*N
    A = [[0]*M for i in range(N)]

    for i in range(N):
        C[i] = CA[(M + 1)*i]
        for j in range(M):
            A[i][j] = CA[(M + 1)*i + j + 1]
    
    B = [0]*M
    for i in range(N):
        for j in range(M):
            B[j] += A[i][j]
    for i in range(M):
        if B[i] < X:
            print(-1)
            return

    ans = sum(C)
    for i in range(2**N):
        B = [0]*M
        price = 0
        for j in range(N):
            if (i >> j) & 1 == 1:
                price += C[j]
                for k in range(M):
                    B[k] += A[j][k]
        found = True
        for j in range(M):
            if B[j] < X:
                found = False
                break
        if found:
            ans = min(ans, price)
    print(ans)

if __name__ == '__main__':
  main()

Solution (Python):
from sys import stdin
import numpy as np

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = []
    for i in range(2 ** n):
        price = 0
        skill = []

        for j in range(n):
            if ((i >> j) & 1):
                price += a[j][0]
                skill.append(a[j][1:])
        np_skill = np.array(skill)
        skill_sum = np.sum(np_skill, axis=0)\
                        if np_skill.shape[0] > 1 else np_skill

        if skill_sum.size != 0 and (skill_sum >= x).all():
            res.append(price)

    if not res: return print('-1')

    return print(min(res))

if __name__ == '__main__':
    main()

Solution (Python):
n, m, x = map(int, input().split())
b = 10**18
tm = []
for i in range(n):
    tm.append(list(map(int, input().split())))
for i in range(2**n):
    c = [0 for i in range(m)]
    sum = 0
    for j in range(n):
        if (i >> j) & 1:
            sum += tm[j][0]
            for k in range(m):
                c[k] += tm[j][k+1]
    if min(c) >= x:
        b = min(b, sum)
if b == 10**18:
    print('-1')
else:
    print(b)

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

default = 10 ** 5 * 12 + 1
min_money = default

for bits in range(1 << N):
    money = 0
    algo = [0] * M
    for i in range(N):
        if bits >> i & 1 == 1:
            money += books[i][0]
            for j in range(M):
                algo[j] += books[i][j + 1]

    if min(algo) >= X:
        min_money = min(min_money, money)

print('-1' if min_money == default else min_money)

Solution (Python):
n,m,x=map(int,input().split())
b=[list(map(int,input().split())) for _ in range(n)]
ans = 100000000
for i in range(1<<n):
    money = 0
    s=[0]*m
    for j in range(n):
        if(i>>j)&1:
            money +=b[j][0]
            for k in range(1,m+1):
                s[k-1]+=b[j][k]
    if min(s)>=x:
        ans=min(ans,money)
if ans != 100000000:
    print(ans)
else:
    print(-1)

Solution (Python):
N, M, X = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
kouho = []
for i in range(2**N):
  skill = [0]*M
  price = 0
  for j in range(N):
    if ((i>>j) & 1):
      skill = [x+y for (x, y) in zip(skill, A[j][1:])]
      price += A[j][0]
  flag = 1
  for k in skill:
    if k < X:
      flag = 0
  if flag:
    kouho.append(price)
if len(kouho):
  print(min(kouho))
else:
  print(-1)

Solution (Python):
n,m,x = map(int,input().split())
c = [0]*n
a = []
ans = float('inf')

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

for bit in range(1<<n):
    s = [0]*m
    sumnum = 0
    for i in range(n):
        if 1 & (bit>>i):
            sumnum += c[i]
            for j in range(m):
                s[j] += a[i][j]
    flag = True
    for k in range(m):
        if s[k] < x:
            flag = False
            break
    if flag:
        ans = min(ans, sumnum)

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

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

n,m,x = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(n)]
ans = float('inf')
for num in range(1,n+1):
    for e in combinations(range(n),num):
        cost = 0
        under = [0 for _ in range(m)]
        for f in e:
            cost += c[f][0]
            for i in range(m):
                under[i] += c[f][i+1]
        if min(under) >= x:
            ans = min(ans,cost)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):



def main():
    import sys
    input = sys.stdin.readline

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

    for i in range(n):
        bi = list(map(int, input().split()))

        ci = bi[0]
        c.append(ci)

        ai = bi[1:]
        a.append(ai)

    ans = float('inf')

    
    
    for i in range(1 << n):
        cost = 0
        tmp = [0 for _ in range(m)]

        for j in range(n):
            
            if (i >> j & 1):
                cost += c[j]

                for index, aii in enumerate(a[j]):
                    tmp[index] += aii

        if min(tmp) >= x:
            ans = min(ans, cost)

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


if __name__ == '__main__':
    main()

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

def main():
    n,m,x = map(int,input().split())
    c = [list(map(int,input().split())) for _ in range(n)]
    ans = float('inf')
    for num in range(1,n+1):
        for e in combinations(range(n),num):
            cost = 0
            under = [0 for _ in range(m)]
            for f in e:
                cost += c[f][0]
                for i in range(m):
                    under[i] += c[f][i+1]
            if min(under) >= x:
                ans = min(ans,cost)
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)
 
    
if __name__ == "__main__":
    main()

Solution (Python):

from itertools import product

import numpy as np


def main():
    n, m , x = map(int, input().split())
    c_list = []
    a_list = []
    for _ in range(n):
        c, *a = list(map(int, input().split()))
        a_list.append(a)
        c_list.append(c)
    
    ans = float("inf")
    for pattern in product((0,1), repeat=n):
        arr = np.array([a_list[i] for i in range(n) if pattern[i] == 1])
        if arr.sum(axis=0).min() >= x:
            cost = sum([c_list[i] for i in range(n) if pattern[i] == 1])
            ans = min(ans, cost)
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Solution (Python):


import itertools
import numpy as np


def main():

    n, m, x= map(int, input().split())
    matrix = np.array([list(map(int, input().split())) for _ in range(n)], dtype=np.int32)

    out = 10**18
    for i in itertools.product([False,True], repeat=n):
        row_sum = np.sum(matrix[np.where(i)], axis=0)
        if m == np.count_nonzero(row_sum[1:] >= x):
            out = min(out, row_sum[0])

    if out == 10**18:
        print('-1')
    else:
        print(out)


if __name__ == '__main__':
    main()

Solution (Python):
n, m, x = [int(x) for x in input().split()]
c = []
a = []
count = 0

for i in range(n):
    tmp = [int(x) for x in input().split()]
    c.append(tmp.pop(0))
    a.append(tmp)

min = sum(c)+1

for i in range(1<<n):
    cost = 0
    skill = [0]*m
    for j in range(n):
        s = []
        if(i>>j&1):
            cost += c[j]
            for k in range(m):
                skill[k] += a[j][k]
    for s in skill:
        if(s < x):
            break
    else:
        if(cost < min):
            min = cost

if(min == sum(c)+1):
    print('-1')
else:
    print(min)

Solution (Python):
n, m, x = [int(x) for x in input().split()]
c = []
a = []
count = 0

for i in range(n):
    tmp = [int(x) for x in input().split()]
    c.append(tmp.pop(0))
    a.append(tmp)

min = sum(c)+1

for i in range(1<<n):
    cost = 0
    skill = [0]*m
    for j in range(n):
        s = []
        if(i>>j&1):
            cost += c[j]
            for k in range(m):
                skill[k] += a[j][k]
    for s in skill:
        if(s < x):
            break
    else:
        if(cost < min):
            min = cost

if(min == sum(c)+1):
    print('-1')
else:
    print(min)

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



ans=10000000000000
for j in range(1,2**(N+1)-1):
    combinationlist=list(map(int, [i for i in format(2**(N+1)+j,'b')]))
    del combinationlist[0]
    sumoflist=[sum(combinationlist[s]*List[s][k] for s in range(N)) for k in range(M+1)]
    flag=True
    for t in range(1,M+1):
        if sumoflist[t]<X:
            flag=False
            break
    if flag and sumoflist[0]<ans:
        ans=sumoflist[0]

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

Solution (Python):


import sys
import itertools
import numpy
n,m,x  = map(int, input().split())
zentan = itertools.product([0,1],repeat = n)
condi  = []
for i in range(n):
    ln = list(map(int, input().split()))
    condi.append(ln)
min_cost = 10**10
for i in zentan:
    cost = 0
    skills= [0]*m
    
    for n1, n2 in enumerate(i):
        cost += condi[n1][0]*n2
        
        for n3 in range(m): 
            skills[n3] += condi[n1][n3+1]*n2
    if min(skills) >= x and cost < min_cost:
        min_cost = cost
    
        

            
            
if min_cost<10**10:
    print(min_cost)
else:
    print('-1')

Solution (Python):

def main():
    import sys, itertools
    import numpy as np
    N,M,X = map(int, sys.stdin.readline().split())
    L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
    
    ans =-1
    for i in range(2**N):
        result = np.array([0 for _ in range(M+1)])
        for j in range(N): 
            if (i >> j) & 1==1:
                result += np.array(L[j])
        if np.all(result[1:] >=X):
            
            if ans ==-1 or result[0] < ans:
                ans = result[0]
    print(ans)
if __name__=='__main__':
    main()

Solution (Python):
n, m, x = map(int, input().split())
INF = 10 ** 18  
ans = INF
li = []
for i in range(n):
    li.append(list(map(int, input().split())))


for i in range(2 ** n):
    cost = 0
    know = [0]*m  
    for j in range(n):  
        if ((i >> j) & 1):  
            
            cost += li[j][0]
            for k in range(m):
                know[k] += li[j][k + 1]

    knowbool = True
    for i in range(m):  
        if (know[i] < x):
            knowbool = False

    if (knowbool):
        ans = min(ans, cost)


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

Solution (Python):



def main():
    from itertools import product
    import sys
    input = sys.stdin.readline

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

    for i in range(n):
        bi = list(map(int, input().split()))

        ci = bi[0]
        c.append(ci)

        ai = bi[1:]
        a.append(ai)

    ans = float('inf')

    for p in list(product(range(2), repeat=n)):
        tmp = [0 for _ in range(m)]
        cost = 0

        for index, pi in enumerate(p):
            if pi == 1:
                for idx, aii in enumerate(a[index]):
                    tmp[idx] += aii

                cost += c[index]

        is_ok = True

        for t in tmp:
            if t < x:
                is_ok = False
                break

        if is_ok:
            ans = min(ans, cost)

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


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    from itertools import product
    import sys
    input = sys.stdin.readline

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

    for i in range(n):
        bi = list(map(int, input().split()))

        ci = bi[0]
        c.append(ci)

        ai = bi[1:]
        a.append(ai)

    ans = float('inf')

    for p in list(product(range(2), repeat=n)):
        tmp = [0 for _ in range(m)]
        cost = 0

        for index, pi in enumerate(p):
            if pi == 1:
                for idx, aii in enumerate(a[index]):
                    tmp[idx] += aii

                cost += c[index]

        is_ok = True

        for t in tmp:
            if t < x:
                is_ok = False
                break

        if is_ok:
            ans = min(ans, cost)

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


if __name__ == '__main__':
    main()

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

INF = 10 ** 9
ans = INF
c = [0] * n
a = [[] for _ in range(n)]
for i in range(n):
    books = list(map(int, input().split()))
    c[i] = books[0]
    a[i] = books[1:]

for i in range(1 << n):
    score = [0] * m
    value = 0
    for k in range(n):
        if i >> k & 1:
            value += c[k]
            for j in range(m):
                score[j] += a[k][j]
    ok = True
    for scores in score:
        if scores < x:
            ok = False
    if ok:
        ans = min(ans, value)

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