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):
    Z = list(map(int, input().split()))
    C.append(Z[0])
    A.append(Z[1:])

ans = 10**12
for i in range(1<<n):
    rikai  = [0] * m
    cost = 0
    bs = bin(i)[2:]
    bs = bs.zfill(n)
    
    for j,b in enumerate(bs):
        if b == "1":
            
            cost += C[j]
            for k in range(m):
                rikai[k] += A[j][k]            
    a = sum([1 for r in rikai if r >= x])
    if a == m:
        ans = min(ans,cost)
print(ans if ans != 10**12 else -1)

Solution (Python):
def resolve():
    import itertools
    impossible = 10 ** 20
    n, m, x = map(int, input().split())
    ans = impossible
    books = [None] * n
    for i in range(n):
        books[i] = list(map(int, input().split()))
    for i in list(itertools.product([True, False], repeat=n)):
        u = [0] * m
        yen = 0
        for index, j in enumerate(i):
            if not j:
                continue
            yen += books[index][0]
            for k in range(m):
                u[k] += books[index][k + 1]
        for j in u:
            if j < x:
                break
        else:
            ans = min(yen, ans)
    print(ans if ans < impossible else -1)


if __name__ == '__main__':
    resolve()

Solution (Python):
import numpy as np
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]
INF = 10**30
min_cost = INF
for pattern in range(1<<N):
    skills = np.array([0]*M)
    cost = 0
    for i in range(N):
        if pattern >> i & 1:
            skil = np.array(books[i][1:])
            skills += skil
            cost += books[i][0]
    if min(skills) >= X and cost < min_cost:
        min_cost = cost
if min_cost == INF:
    print(-1)
else:
    print(min_cost)

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

ans=10**9
for i in range(2**n):
    s=format(i,'b')
    Z=s.zfill(n)
    cost=0
    M=[0]*m
    for j in range(n):
        if Z[j]=='1':
            cost+=X[j][0]
            for k in range(m):
                M[k]+=X[j][1+k]
    if all([m>=x for m in M]):
        ans=min(ans,cost)

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

Solution (Python):
import itertools
import numpy as np

N, M, X = map(int, input().split())
books = list()
for _ in range(N):
    books.append(list(map(int, input().split())))
    
A = [False, True]
combinations = list(itertools.product(A, repeat=N))
books_array = np.array(books)
amount = float('inf')
check = False
for comb in combinations:
    array = books_array[np.array(comb).T]
    amo = array[:, 0].sum()
    if np.all(array[:, 1:].sum(axis=0) >= X) and amo < amount:
        amount = amo
        check = True

if check:
    print(amount)
else:
    print(-1)

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

ans = INF
for i in range(2**n):
    tmp = 0
    tmp_l = [0]*m
    for j in range(n):
        if i & (1<<j):
            tmp += ca[j][0]
            for k in range(m):
                tmp_l[k] += ca[j][1+k]
    if min(tmp_l) >= x:
        ans = min(ans, tmp)
if ans == INF:
    ans = -1
print(ans)

Solution (Python):
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M,X = LMIIS()
    books = []
    for _ in range(N):
        books.append(LMIIS())
    up = 12 * 10**5 + 1
    min_cost = up
    for i in range(2**N):
        algo = [0]*M
        cost = 0
        for j in range(N):
            if i & (2**j):
                cost += books[j][0]
                for k in range(M):
                    algo[k] += books[j][k+1]
        if min(algo) < X:
            continue
        min_cost = min(min_cost,cost)
    print(min_cost if min_cost != up else -1)

        



if __name__ == '__main__':
    main()

Solution (Python):

def format(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out


def format0(X, n, m):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    if len(out) < m:
        out = "0" * (m - len(out)) + out
    return out

n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
mo=10000000000000
import numpy
for i in range(1,pow(2,n)):
  i=format0(i,2,n)
  money=0
  aaa=[0]*m
  aaa=numpy.array(aaa)
  for j in range(n):
    if i[j]=="1":
      money+=ca[j][0]
      aaa = aaa + numpy.array(ca[j][1:])
  if aaa.min()>=x:
    mo=min(mo,money)
  else:
    if i=="1"*n:
      print("-1")
      exit()
print(mo)

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


def calc(isBuy):
    global min_cost
    understands = [0 for _ in range(M)]
    cost = 0
    for i in range(N):
        if isBuy[i]:
            cost += Cs[i]
            for j in range(M):
                understands[j] += As[i][j]

    isClear = True
    for und in understands:
        if und < X:
            isClear = False

    if isClear:
        min_cost = min(min_cost, cost)


def search(isBuy):
    if len(isBuy) == N:
        calc(isBuy)
    else:
        search(isBuy + [True])
        search(isBuy + [False])


min_cost = float('inf')
search([])

if min_cost < float('inf'):
    print(min_cost)
else:
    print(-1)

Solution (Python):
from collections import deque
N, M, X = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(N)]
ans = 10**20
q = deque()
q.append([])
while q:
  x = q.pop()
  if len(x) == N:
    U = [0]*M
    i = 0
    while i < N:
      if x[i]:
        j = 0
        while j < M:
          U[j] += B[i][j+1]
          j += 1
      i += 1
    if len(list(filter(lambda x:x< X, U))) < 1:
      ans = min(ans, sum([B[i][0] if x[i] else 0 for i in range(N)]))
  else:
    q.append(x+[True])
    q.append(x+[False])
print(ans if ans < 10**20 else -1)

Solution (Python):
n,m,x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
ans = float("inf")
for i in range(1 << n):
    money = 0
    skill = [0]*m
    for j in range(n):
        if ((i >> j) & 1) == 1:
            money += c[j][0]
            for k in range(1,m+1):
                skill[k-1] += c[j][k]
    if all(l >= x for l in skill):
        ans = min(ans,money)
print(-1 if ans==float("inf") else ans)

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

C = []
A = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    c = tmp[0]
    a = tmp[1:]
    C.append(c)
    A.append(a)
A = np.array(A)

ans = 10**18
for bit in range(1 << N):
    cost = 0
    V = np.array([0] * M)
    for i in range(N):
        if bit & 1 << i:
            cost += C[i]
            V += A[i]
    if np.all(V >= X):
        ans = min(ans, cost)
if ans == 10**18:
    print(-1)
else:
    print(ans)

Solution (Python):
N,M,X = map(int,input().split())
CA = [list(map(int,input().split())) for _ in range(N)]
judge = False
ans = float('inf')
for i in range(2**N):
  lis = []
  for j in range(N):
    if (i>>j)&1:
      lis.append(CA[j])
  
  rikaido = [0]*M
  tmp_ans = 0
  tmp_judge = True
  for j in lis:
    tmp_ans += j[0]
    for k,x in enumerate(j[1:]):
      rikaido[k] += x
  
  for j in rikaido:
    if j>=X:
      continue
    else:
      tmp_judge = False
      break
  
  if tmp_judge:
    judge = True
    ans = min(ans,tmp_ans)
    
if judge:
  print(ans)
else:
  print(-1)

Solution (Python):
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):
    num=format(i,"b").zfill(n)
    C=[0 for _ in range(m)]
    point=0
    for j,k in enumerate(num):
        if k=="1":
            c,B=A[j][0],A[j][1:]
            for v,s in enumerate(B):
                C[v] +=s
            point +=c
    flag=1
    for i in range(m):
        if C[i]>=x:continue
        else:
            flag=0
            break
    if flag:ans=min(ans,point)
print(ans if ans!=10**10 else -1)

Solution (Python):


import sys

sys.setrecursionlimit(210000)
MAX_VAL = 1000000000


def search(idx, books, reqs):
  if max(reqs) <= 0:
    return 0

  if idx >= len(books):
    return MAX_VAL

  cost0 = search(idx + 1, books, reqs)

  reqs = [r - s for r, s in zip(reqs, books[idx][1:])]
  cost1 = search(idx + 1, books, reqs) + books[idx][0]

  return min(cost0, cost1)


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

  if cost < MAX_VAL:
    print(cost)
  else:
    print(-1)


if __name__ == '__main__':
  main()

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
from collections import defaultdict

N, M, X = map(int, input().split())
B = []
for i in range(N):
    B.append(list(map(int, input().split())))
ans = 10**18
for i in range(1<<N):
    c = 0
    r = [0]*M
    for j in range(N):
        if (i>>j)&1:
            c += B[j][0]
            for k in range(1, M+1):
                r[k-1] += B[j][k]
    if all([x >= X for x in r]):
        ans = min(ans, c)
if ans == 10**18:
    ans = -1
print(ans)

Solution (Python):
n, m, x = map(int, input().split())
a_list = []
c_list = []
for i in range(n):
    a = [int(i) for i in input().split()]
    a_list.append(a[1:])
    c_list.append(a[0])
ans = -1
for j in range(2 ** n):
    ans_list = [0] * m
    cost = 0
    for i in range(n):
        if j & (2 ** i) > 0:
            for index, k in enumerate(a_list[i]):
                ans_list[index] += k
            cost += c_list[i]
    if sum([1 for i in ans_list if i >= x]) == m:
        if ans == -1:
            ans = cost
        else:
            ans = min(ans, cost)
print(ans)

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

ans = 10**10
for i in range(2 ** n):
    state = [0] * n
    for j in range(n):
        state[j] = (i >> j) & 1
    
    num = [0] * m
    val = 0

    for j in range(n):
        if state[j] == 1:
            for k in range(m):
                num[k] += c[j][k+1]
            val += c[j][0]

    flag = True
    for j in range(m):
        if num[j] < x:
            flag = False
            break
    if flag:
        ans = min(ans, val)

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

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

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

ans = -1

for i in range(2 ** N):
    A = [0] * M
    buy = 0
    for j in range(N):
        if (i >> j) & 1:
            buy += ca[j][0]
            for k in range(1, M + 1):
                A[k - 1] += ca[j][k]

    for i in range(M):
        if A[i] < X:
            break

        if i == M - 1:
            if ans == -1:
                ans = buy
            else:
                ans = min(ans, buy)

print(ans)

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

unds = [[0 for _ in range(M + 1)]]

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

    new_unds = list()
    for und in unds:
        new_und = copy.copy(und)
        new_und[-1] += C
        for m in range(M):
            new_und[m] += A[m]
        new_unds.append(new_und)
    unds.extend(new_unds)

minc = 10e10
for und in unds:
    for m in range(M):
        if und[m] < X:
            break
    else:
        if minc > und[-1]:
            minc = und[-1]

if minc > 10e9:
    minc = -1

print(minc)

Solution (Python):
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]





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

ma = int(1e18)
ans = ma
for b in range(1 << N):
    ind = 1
    dp = [0]*M
    res = 0
    while b > 0:
        if b % 2 == 1:
            c = C[ind]
            l = A[ind]
            for i in range(M):
                dp[i] += l[i]
            res += c
            
        b //= 2
        ind += 1
    if all([e >= X for e in dp]):
        ans = min(ans, res)


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

Solution (Python):
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

min_price = 100000000000
for i in range(2 ** N):
    price = 0
    understand = [0] * M
    for j in range(N):  
        if ((i >> j) & 1):  
            price += C[j]
            for k, u in enumerate(A[j]):
                understand[k] += u

    if min(understand) >= X:
        min_price = min(min_price, price)

if min_price == 100000000000:
    print(-1)
else:
    print(min_price)

Solution (Python):
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
ans=10**9
for i in range(2**n):
  cnt=[0]*m
  kari=0
  for j in range(n):
    if (i>>j)&1:
      for k in range(m):
        cnt[k]+=ca[j][k+1]
      kari+=ca[j][0]
    else:
      pass
  if min(cnt)>=x:
    ans=min(ans,kari)
if ans==10**9:
  print(-1)
else:
  print(ans)

Solution (Python):
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for i in range(N)]
ans=10**18
x=[0]*M
for i in range(1,2**N):
  _ans=0
  _x=x[:]
  f=True
  for j in range(N):
    if i%2==1:
      for k,a in enumerate(CA[j]):
        if k==0:
          _ans+=a
        else:
          _x[k-1]+=a
    i=i//2
  for _ in _x:
    if _<X:
      f=False
      break
  if f:
    ans=min(ans,_ans)
if ans==10**18:
  ans=-1
print(ans)

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

    
opt_cost = 10 ** 10    
    
for i in range(2 ** N):
    temp_num = i
    lst_ = []
    for j in range(N):
        if temp_num % 2 == 0:
            lst_.append(0)
        else:
            lst_.append(1)
        temp_num = temp_num // 2
        
        
    temp_cost = 0
    temp_ability = [0 for n in range(M)]
    
    for k in range(N):
        if lst_[k] == 1:
            temp_cost += cost_[k]
            for a in range(M):
                temp_ability[a] += A[k][a]
    
    if min(temp_ability) >= X:
        if temp_cost <= opt_cost:
            opt_cost = temp_cost

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

Solution (Python):
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n, m, x = nm()
l = [nl() for _ in range(n)]
ans = 10**10
for bit in range(1<<n):
    cst = 0
    g = [0]*m
    for i in range(n):
        if bit & (1<<i):
            f = l[i]
            cst += f[0]
            for j in range(m):
                g[j] += f[j+1]
    if min(g) >= x:
        ans = min(ans, cst)
print(ans if ans < 10**10 else -1)

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

cost = 10 ** 7

for i in range(2 ** N):
    score = [0] * M
    r = str(format(i, 'b')).zfill(N)
    c = 0
    for j in range(N):
        if r[j] == '1':
            c += ABC[j][0]
            for k in range(M):
                score[k] = score[k] + ABC[j][1 + k]
    j = 1
    for k in range(M):
        if score[k] < X:
            j = 0
    if j == 1 and c < cost:
        cost = c
if cost == 10 ** 7:
    print(-1)
else:
    print(cost)

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


bit_len = n
INF = 10 ** 7
ans = INF


for num in range(2 ** bit_len):
    tmp = [0 for i in range(m)]
    c = 0
    for i in range(bit_len):
        if num & (1 << i):
            
            c += ca[i][0]
            for j in range(1, m+1):
                tmp[j-1] += ca[i][j]
    if min(tmp) >= x:
        ans = min(ans, c)
if ans == INF:
    print(-1)
else:
    print(ans)

Solution (Python):

n,m,x = list(map(int,input().split()))
c = [list(map(int,input().split())) for i in range(n)]
inf=float("inf")
ret = inf

from itertools import product
for flg_list in list(product([0,1],repeat=n)):
    rikaido_list = [0] * m
    cost = 0
    flg = True
    for i,v in enumerate(flg_list):
        if v == 1:
            cost += c[i][0]
            rikaido_list = [i+j for i,j in zip(rikaido_list,c[i][1::])]
    for i in rikaido_list:
        if i < x:
            flg = False
            break
    if flg:
        ret = min(ret,cost)

from math import isinf
if isinf(ret):
    print(-1)
else:
    print(ret)

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

ans = 10**8
for i in range(2**N):
    c = 0
    skill = [0]*M
    for j in range(N):
        if ( (i>>j) & 1 ):
            c += K[j][0]
            for k in range(1,M+1):
                skill[k-1] += K[j][k]
    skill.sort()
    if skill[0] >= X:
        ans = min(c,ans)

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

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

L = []
for _ in range(N):
  x = input().split()
  x = [int(y) for y in x]
  L.append(x)
  
cost = []

for i in range(2**N):
    list = []
    point = [0 for _ in range(M)]
    c = 0
    for j in range(N):
        if ((i >> j)&1):
            list.append(L[j])
    for x in list:
        c +=x[0]
        for i in range(1,M+1):
            point[i-1] += x[i]
    if min(point) >= X:
        cost.append(c)

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

Solution (Python):
import numpy as np
n,m,x=map(int,input().split())
N=1<<n
C=[]
A=[0 for i in range(n)]
for i in range(n):
    tmpc,*tmpa=map(int,input().split())
    C.append(tmpc)
    tmpa=np.array(tmpa,dtype=np.int64)
    A[i]=tmpa

ans=10**9
for bit in range(N):
    comp=np.zeros(m,dtype=np.int64)
    tmpans=0
    for i in range(n):
        if bit&(1<<i):
            comp+=A[i]
            tmpans+=C[i]
    flag=True
    for i in range(m):
        if comp[i]<x:
            flag=False
    if flag:
        ans=min(ans,tmpans)

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

Solution (Python):
n,m,x=map(int,input().split())
c=[]
a=[]
for _ in range(n):
  ca=list(map(int,input().split()))
  c.append(ca[0])
  a.append(ca[1:])
ans=13*pow(10,5)
for i in range(2**n):
  rikai=[0]*m
  kin=0
  for j in range(n):
    if ((i>>j) & 1):
      for k in range(m):
        rikai[k]+=a[j][k]
      kin+=c[j]
  if min(rikai)>=x:
    ans=min(ans,kin)
print(ans if ans<13*pow(10,5) else -1)

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

def calc(p):
    ret = 0
    cnt = [0] * M
    for i, v in enumerate(p):
        if v == 1:
            for ia, a in enumerate(A[i]):
                cnt[ia] += a
            ret += C[i]
    return ret if all(i >= X for i in cnt) else 10 ** 30
    

ans = 10 ** 30
for p in product(range(2), repeat=N):
    ans = min(ans, calc(p))

print(ans if ans < 10 ** 30 else -1)

Solution (Python):
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = f_inf
    for pattern in product([0, 1], repeat=n):
        A = [0 for _ in range(m)]
        cost = 0
        for idx, p in enumerate(pattern):
            if p == 1:
                cost += C[idx][0]
                for i in range(m):
                    A[i] += C[idx][i + 1]

        for a in A:
            if a < x:
                break
        else:
            res = min(res, cost)

    if res == f_inf:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
N,M,X = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(N)]
ans = float('inf')
for bit in range(2**N):
    temp = [0]*M
    money = 0
    for i in range(N):
        if bit & (1<<i):
            money += ca[i][0]
            for idx,rikai in enumerate(ca[i][1:]):
                temp[idx] += rikai
            
    ok = True
    for x in temp:
        if x < X:
            ok = False
    
    if ok:
        ans = min(ans,money)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Solution (Python):
n,m,zz = [int(x) for x in input().split()]
li = []
for _ in range(n):
    z = [int(x) for x in input().split()]
    li.append(z)
ans = 10**10
for i in range(2**n):
    y = [0]*m
    num = 0
    for j in range(n):
        if (i&(1<<j)):
            for k in range(m):
                y[k]+=li[j][k+1]
            num+=li[j][0]
    if min(y)>=zz:
        ans = min(ans,num)
if ans==10**10:
    ans = -1
print(ans)

Solution (Python):

def solve(N, M, X, books):
    ans = 10 ** 10
    f = "{:0" + str(N) + "b}"
    for k in range(2 ** N):
        cost = 0
        bins = f.format(k)
        powers = [0 for _ in range(M)]
        for i, b in enumerate(bins):
            if b == "1":
                cost += books[i][0]
                for m in range(M):
                    powers[m] += books[i][1][m]

        if all(p >= X for p in powers):
            ans = min(ans, cost)

    if ans == 10 ** 10:
        return -1
    return ans


if __name__ == "__main__":
    N, M, X = tuple(map(int, input().split(" ")))
    books = []
    for _ in range(N):
        k = list(map(int, input().split(" ")))
        books.append((k[0], k[1:]))
    print(solve(N, M, X, books))

Solution (Python):

import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n,m,x = na()
    cs = []
    As = []
    for _ in range(n):
        ca = na()
        cs.append(ca[0])
        As.append(ca[1:])
    ans = -1
    for i in range(pow(2,n)):
        rikais = [0 for _ in range(m)]
        money = 0
        for j in range(n):
            if ((i>>j) & 1):
                money += cs[j]
                for k in range(m):
                    rikais[k] += As[j][k]
        flag = 1
        for l in range(m):
            if rikais[l] < x:
                flag = 0
                break
        if flag:
            if ans == -1:
                ans = money
            else:
                ans = min(ans,money)
    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product
n, m, X = map(int, input().split())
ca = [tuple(map(int, input().split()))for _ in range(n)]
INF = 10**18
ans = INF
for x in product([0, 1], repeat=n):
    cost = 0
    ms = [0]*m
    for i in range(n):
        if x[i] == 0:
            continue
        c, *a = ca[i]
        cost += c
        for j in range(m):
            ms[j] += a[j]

    if all(X <= y for y in ms) and cost < ans:
        ans = cost


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

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


ans = 10 ** 19
for b in range(2 ** n):
  aa = [0] * m
  amn = 0
  for i in range(n):
    if (b >> i) & 1:
      amn += CA[i][0]
      for k in range(m):
        aa[k] += CA[i][k + 1]
  if all(a >= x for a in aa):
    ans = min(ans, amn)  

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

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

    ans = float('inf')
    for i in range(1<<N):
        score = [0] * M
        tmp = []
        money = 0
        for j in range(N):
            if (i >> j) & 1:
                tmp.append(j)
                money += C[j]
        
        for t in tmp:
            for k in range(len(A[t])):
                score[k] += A[t][k]
        flag = True
        for s in score:
            if s < X:
                flag = False

        if flag:
            ans = min(ans, money)
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)



if __name__ == "__main__":
    main()

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

A = []
C = []

for i in range(N):
    a = list(map(int, input().split()))
    C.append(a[0])
    A.append(a[1:])
flag = False
ans = 12 * 10**6
for i in range(2**N):
    s = 0
    rikai = [0] * M
    for j in range(N):
        if ((i >> j) & 1):
            s += C[j]
            for k in range(M):
                rikai[k] += A[j][k]

        if (len([x for x in rikai if x >= X])) == M:
            flag = True
            ans = min(ans, s)

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

Solution (Python):


import sys

class CSkillUp:
    def solve(self, tc=0):
        n, m, x = [int(_) for _ in input().split()]
        a = []
        c = []
        for _ in range(n):
            ci, *line = [int(_) for _ in input().split()]
            a.append(line)
            c.append(ci)

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

            if min(und) >= x and cost < min_cost:
                min_cost = cost

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




solver = CSkillUp()
input = sys.stdin.readline

solver.solve()

Solution (Python):
import itertools

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

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

minmoney = -1
for use in itertools.product([0, 1], repeat=n):
    for j in range(m):
        if sum([a[i][j]*use[i] for i in range(n)]) < x:
            break
    else:
        money = sum([c[i]*use[i] for i in range(n)])
        if minmoney == -1:
            minmoney = money
        else:
            minmoney = min(minmoney, money)

print(minmoney)

Solution (Python):
n, m, x = map(int,input().split())
books = []
for _ in range(n):
    books.append(list(map(int,input().split())))
price = float('inf')

for i in range(2**n):
    prtmp = 0
    skill = [0] * m
    for j in range(n):
        if i >> j & 1:
            prtmp += books[j][0]
            for s in range(m):
                skill[s] += books[j][s+1]
    clear = True
    for s in skill:
        if s < x:
            clear = False
            break
    if clear:
        price = min(price,prtmp)

print(-1 if price == float('inf') else price)

Solution (Python):



def solve(N, M, X, C, A):
    from itertools import product, compress
    ans = float('inf')
    for selectors in product([0, 1], repeat=N):
        cost = sum(compress(C, selectors), 0)
        x = [0] * M
        for a in compress(A, selectors):
            for i, aa in enumerate(a):
                x[i] += aa
        if all(xx >= X for xx in x):
            ans = min(ans, cost)
    return -1 if ans == float('inf') else ans


def main():
    N, M, X = list(map(int, input().split()))
    C, A = [], []
    for _ in range(N):
        c, *a = map(int, input().split())
        C.append(c)
        A.append(a)
    print(solve(N, M, X, C, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]





N, M ,X = mi()
CA = [li() for _ in range(N)]

B = 2**N
ans = float('inf')
for i in range(B):
    cnt = [0]*M
    flag = 1
    kane = 0
    for j in range(N):
        if i & 1 << j:
            kane += CA[j][0]
            for k in range(M):
                cnt[k] += CA[j][k+1]
    
    for k in range(M):
        if cnt[k] < X:
            flag = 0
            break
    if flag:
        ans = min(ans, kane)
if ans == float('inf'):
    print(-1)
    exit()
print(ans)

Solution (Python):
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

inf = 10 ** 20
ans = inf
for bit in range(2**n):
    yen = 0
    x = [0] * m
    for i in range(n):
        if bit >> i & 1 == 1:
            for j in range(m):
                x[j] += A[i][j]
            yen += C[i]
    if all(i >= X for i in x) and ans > yen:
        ans = yen
if ans == inf:
    ans = -1
print(ans)