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())
c=[list(map(int,input().split())) for _ in range(n)]
l=[]
for i in range(2**n):
    l.append(format(i,'b').zfill(n))
l1=[]
for i in range(len(l)):
    s=[0]*(m+1)
    for j in range(n):
        if l[i][j]=='1':
            for k in range(m+1):
                s[k]+=c[j][k]

    for o in range(1,m+1):
        if s[o]<x:break
        if o==m:l1.append(s[0])
if len(l1)==0:print(-1) 
else:print(min(l1))

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

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

for i in range(N):
  a=[int(x) for x in input().rstrip().split()]
  l.append(a)

ans=float('inf')
falg=1


A=[0 for x in range(M)]
for i in range(2**N):
  cost=0
  flag=1
  
  for j in range(N):
    if i>>j & 1:
      now=l[j]
      cost+=now[0]
      for t in range(M):
        A[t]+=now[t+1]

  for s in range(M):
    if X<=A[s]:
      continue
    else:
      flag=0
      break
  if flag==1:
    ans=min(ans,cost)
  
  A=[0 for v in range(M)]

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

Solution (Python):
import numpy as numpy
n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for i in range(n)]
ans = float('inf')
for i in range(2 ** n):
    cost = 0
    exp = numpy.array([0] * m)
    for j, b in enumerate(books):
        if i >> j & 1:
            continue
        cost += b[0]
        exp = exp + numpy.array(b[1:])
    if (exp < x).any():
        continue
    ans = min(cost, ans)
if ans == float('inf'):
    ans = -1
print(ans)

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

nedan = 0
nedan_mazi = 12*10**15
flag = 0

for i in range(2**N):

    bag = []
    for j in range(N):
        if (i >> j) & 1:
            bag.append(j)

    rikai = [0] * M
    for t in bag:
        for k in range(M):
            rikai[k] += book_list[t][k+1]

    for p in range(M):
        flag=0
        if rikai[p] < X:
            flag = 1
            break

    if flag != 1:
        nedan=0
        for s in bag:
            nedan += book_list[s][0]
    else:
        nedan = 12*10**15

    nedan_mazi = min(nedan, nedan_mazi)


if nedan_mazi == 12*10**15:
    nedan_mazi = -1

print(nedan_mazi)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int,input().split()))
def inpm():
    return map(int,input().split())

ans = INF

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

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

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

Solution (Python):
import numpy as np

data = input().split()
n = int(data[0])
m = int(data[1])
x = int(data[2])
data = []
for _ in range(n):
    data.append(np.array(list(map(int,input().split()))))

INF = 10000000
ans = INF
for b in range(2**n):
    value = np.array([0 for _ in range(m+1)])
    b = bin(b)[2:]
    for zero in range(n-len(b)):
        b = "0" + b
    for i in range(n):
        if b[i] == "1":
            value += data[i]
    ok = True
    for i in range(1,m+1):
        if value[i] < x:
            ok = False
    if ok == True and value[0] <= ans:
        ans = value[0]
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)]
result=[]
for i in range(2**N):
    A=[]
    for j in range(N):
        if (i>>j)&1:
            A.append(C[j])
    result.append(A)
inf=float('inf')
ans2=inf

for i in result:
    D=dict()
    ans1=0
    ans3=0
    if i!=[]:
        for j in i:
            ans1+=j[0]
            for k,value in enumerate(j):
                if k!=0:
                    D[k]=D.get(k,0)+value
            
        for j in D.values():
            if j>=X:
                ans3+=1
        if ans3==M:
            ans2=min(ans2,ans1)
if ans2==inf:
    print(-1)
else:
    print(ans2)

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

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

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

Solution (Python):
import itertools
n,m,x=map(int,input().split())
books=[list(map(int,input().split())) for i in range(n)]
ans=10**10
for status in itertools.product(range(2),repeat = n):
    cnt=0
    skill=[0]*m
    for j in range(n):
        if status[j]:
            cnt+=books[j][0]
            for k in range(m):
                skill[k]+=books[j][k+1]
    if min(skill)>=x:
        ans=min(ans,cnt)
if ans==10**10:print(-1)
else:print(ans)

Solution (Python):
from __future__ import annotations

import itertools
import unittest
from dataclasses import dataclass, field, InitVar
from typing import List


def create_order_patterns(n: int):
    return itertools.product(range(2), repeat=n)


@dataclass
class Book:
    id: int
    price: int
    algorithm_points: List[int]


@dataclass
class TakahashiKun:
    border_line: int
    number_of_types_of_algorithms: InitVar[int]
    purchase_amount: int = 0
    algorithm_points: List[int] = field(init=False)

    def __post_init__(self, number_of_types_of_algorithms: int):
        
        self.algorithm_points = [0 for _ in range(number_of_types_of_algorithms)]

    def buy_and_read(self, book: Book) -> None:
        
        self.purchase_amount += book.price

        self.algorithm_points = [p1 + p2 for p1, p2 in zip(self.algorithm_points, book.algorithm_points)]

    def has_read_at_least_one_book(self) -> bool:
        return self.purchase_amount > 0

    def passed_border_line(self) -> bool:
        return all([p >= self.border_line for p in self.algorithm_points])


@dataclass
class TakahashiKunCollection:
    values: List[TakahashiKun] = field(default_factory=list)

    def add(self, single_result: TakahashiKun) -> None:
        self.values.append(single_result)  

    def min_purchase_amount_required_pass(self) -> int:
        passed_takahashi_list = [takahashi for takahashi in self.values if takahashi.passed_border_line()]

        if not passed_takahashi_list:
            return -1

        return min([takahashi.purchase_amount for takahashi in passed_takahashi_list])

    @staticmethod
    def create(number_of_types_of_algorithms: int,
               border_line: int, 
               book_lineup: List[Book], 
               order_patterns) -> TakahashiKunCollection:
        
        takahashi_kun_collection = TakahashiKunCollection()

        for order in order_patterns:
            single_result = TakahashiKun(border_line, number_of_types_of_algorithms)

            for idx, is_buy in enumerate(order):
                if is_buy == 1:
                    single_result.buy_and_read(book_lineup[idx])

            if single_result.has_read_at_least_one_book():
                takahashi_kun_collection.add(single_result)

        return takahashi_kun_collection


def actual(N, M, X, books_info):
    book_lineup = []

    for idx, book_info in enumerate(books_info, start=1):
        book = Book(id=idx, price=book_info[0], algorithm_points=book_info[1:])
        book_lineup.append(book)

    results = TakahashiKunCollection.create(N, X, book_lineup, order_patterns=create_order_patterns(N))

    return results.min_purchase_amount_required_pass()


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

books_info = []
for _ in range(N):
  book_info = list(map(int, input().split()))
  books_info.append(book_info)

print(actual(N, M, X, books_info))

Solution (Python):
from __future__ import annotations

import itertools
import unittest
from dataclasses import dataclass, field, InitVar
from typing import List


def create_order_patterns(n: int):
    return itertools.product(range(2), repeat=n)


@dataclass
class Book:
    id: int
    cost: int
    skill_points: List[int]


@dataclass
class SingleResult:
    border_line: int
    dim: InitVar[int]
    cost: int = 0
    skill_points: List[int] = field(init=False)

    def __post_init__(self, dim: int):
        self.skill_points = [0 for _ in range(dim)]

    def register(self, book: Book):
        self.cost += book.cost

        self.skill_points = [p1 + p2 for p1, p2 in zip(self.skill_points, book.skill_points)]

    def has_item(self) -> bool:
        return self.cost > 0

    def is_satisfy(self) -> bool:
        return all([p >= self.border_line for p in self.skill_points])


@dataclass
class Results:
    values: List[SingleResult] = field(default_factory=list)

    def add(self, single_result: SingleResult) -> None:
        self.values.append(single_result)  

    def min_cost_ok(self) -> int:
        satisfied_books = [book for book in self.values if book.is_satisfy()]

        if not satisfied_books:
            return -1

        return min([book.cost for book in satisfied_books])

    @staticmethod
    def create(dim: int, border_line: int, book_lineup: List[Book], order_patterns) -> Results:
        results = Results()

        for order in order_patterns:
            single_result = SingleResult(border_line, dim)

            for idx, is_buy in enumerate(order):
                if is_buy == 1:
                    single_result.register(book_lineup[idx])

            if single_result.has_item():
                results.add(single_result)

        return results


def actual(N, M, X, books_info):
    book_lineup = []

    for idx, book_info in enumerate(books_info, start=1):
        book = Book(id=idx, cost=book_info[0], skill_points=book_info[1:])
        book_lineup.append(book)

    results = Results.create(N, X, book_lineup, order_patterns=create_order_patterns(N))

    return results.min_cost_ok()


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

books_info = []
for _ in range(N):
  book_info = list(map(int, input().split()))
  books_info.append(book_info)

print(actual(N, M, X, books_info))

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

ans = 10**10
for i in range(1<<n):
    score = 0
    li = [0]*m
    for j in range(n):
        LL = L[j][1:]
        
        if (i>>j)&1:
            score += L[j][0]
            for k in range(m):
                li[k] +=LL[k]
    if all(x >= p for x in li):
        ans = min(ans,score)
if ans != 10**10:
    print(ans)
else:
    print(-1)

Solution (Python):
from __future__ import annotations

import itertools
import unittest
from dataclasses import dataclass, field, InitVar
from typing import List


def create_buy_patterns(n: int):
    return itertools.product(range(2), repeat=n)


@dataclass
class Book:
    id: int
    cost: int
    skill_points: List[int]


@dataclass
class SingleResult:
    border_line: int
    dim: InitVar[int]
    cost: int = 0
    skill_points: List[int] = field(init=False)

    def __post_init__(self, dim: int):
        self.skill_points = [0 for _ in range(dim)]

    def register(self, book: Book):
        self.cost += book.cost

        self.skill_points = [p1 + p2 for p1, p2 in zip(self.skill_points, book.skill_points)]

    def has_item(self) -> bool:
        return self.cost > 0

    def is_ok(self) -> bool:
        return all([p >= self.border_line for p in self.skill_points])


@dataclass(frozen=True)
class Results:
    values: List[SingleResult] = field(default_factory=list)

    def add(self, single_result: SingleResult) -> None:
        self.values.append(single_result)  

    def __len__(self) -> int:
        return len(self.values)

    def __getitem__(self, index: int) -> SingleResult:
        return self.values[index]

    def min_cost_ok(self) -> int:
        border_line_pass_books = [book for book in self.values if book.is_ok()]

        if not border_line_pass_books:
            return -1

        return min([book.cost for book in border_line_pass_books])

    @staticmethod
    def create(dim: int, border_line: int, book_lineup: List[Book], buy_patterns) -> Results:
        results = Results()

        for buy_pattern in buy_patterns:
            single_result = SingleResult(border_line, dim)

            for idx, is_buy in enumerate(buy_pattern):
                if is_buy == 1:
                    single_result.register(book_lineup[idx])

            if single_result.has_item():
                results.add(single_result)

        return results


def actual(N, M, X, books_info):
    book_lineup = []
    for idx, book_info in enumerate(books_info, start=1):
        book = Book(id=idx, cost=book_info[0], skill_points=book_info[1:])
        book_lineup.append(book)

    results = Results.create(N, X, book_lineup, buy_patterns=create_buy_patterns(N))

    return results.min_cost_ok()


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

books_info = []
for _ in range(N):
  book_info = list(map(int, input().split()))
  books_info.append(book_info)

print(actual(N, M, X, books_info))

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

inf = int(1e20)
n, m, x = map(int, input().split())
_ = [[int(x) for x in input().split()] for _ in range(n)]
CA = np.array(_, dtype=int)
ans = inf
for indices in product([0, 1], repeat=n):
    tmp = np.zeros(m + 1, dtype=int)
    for idx, be_used in enumerate(indices):
        tmp += be_used * CA[idx]
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
print(ans if ans != inf else '-1')

Solution (Python):
n,m,x = map(int,input().split())
book = []
import numpy as np
for _ in range(n):
    a = list(map(int,input().split()))
    book.append(a)
ans = float("inf")
for i in range(1,2**n):
    use_book = []
    for j in range(n):
        if (i>>j) &1:
            use_book.append(book[j])
    arr = np.array(use_book)
    arr_sum = np.sum(arr,axis =0)
    true =1
    for i in range(1,m+1):
        if arr_sum[i] < x:
            true = 0
            break
    if true == 1:
        ans = min(ans,arr_sum[0])
if ans == float("inf"):
    ans = -1
print(ans)

Solution (Python):

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

ans = []
for i in range(2**n):
  price = 0
  und = [0 for _ in range(m)]
  for j in range(n):
    if (i >> j) & 1:
      price += c[j][0]
      for k in range(m):
        und[k] += c[j][k+1]
  if all(und[i] >= x for i in range(m)):
    ans.append(price)
    
if ans == []:
  print(-1)
else:
  print(min(ans))

Solution (Python):
n,m,x = list(map(int, input().split()))
c = []
alg = []
for i in range(n):
    tmp = list(map(int, input().split()))
    c.append(tmp[0])
    tmp.pop(0)
    alg.append(tmp)

price_min = -1

for i in range(2**n):
    price = 0
    skill = [0]*m
    skillFlag = True
    buyBin = format(i, '0'+str(n)+'b')
    for j in range(n):
        if buyBin[j] == '1':
            price += c[j]
            for k in range(m):
                skill[k] += alg[j][k]

    for k in range(m):
        if skill[k] < x:
            skillFlag = False
    
    if skillFlag:
        if price_min > price or price_min == -1:
            price_min = price

print(price_min)

Solution (Python):
import numpy as np

N, M, X = map(int, input().split())
C = []
A = [[] for i in range(M)]
resC = []
resA = list(A)

NEW = 0

def update(base):
  
  if base==None:
    return NEW
  return base + NEW

def check(num):
  return num>=X

def check2(*args):
  res = True
  for val in args:
    buf = (val >= X)
    res = res and buf
  return res

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

for i in range(N):
  if i == 0:
    NEW = C[i]
    resC = [0, NEW]
    resA = [[0, A[j][i]] for j in range(M)]
  else:
    NEW = C[i]
    resC = resC + list(map(update, resC))
    for j in range(M):
      NEW = A[j][i]
      resA[j] = resA[j] + list(map(update, resA[j]))

res = list(map(check2, *resA))

if sum(res)==0:
  print(-1)
else:
  print(min(np.asarray(resC)[res]))

Solution (Python):
import itertools
import numpy as np

def calc(aaa, M, X, pattern):
    tmp_price = 0
    for t in pattern:
        price = 0
        sum = np.zeros(M)
        for i in t:
            price += aaa[i][0]
            current = np.array(aaa[i][1:M+1])
            sum = sum + current

        if np.count_nonzero(sum >= X) >= M:
            if tmp_price == 0:
                tmp_price = price
            else:
                tmp_price = min(tmp_price, price)
    
    return tmp_price


def solve(N, M, X, aaa):
    tmp_result = 0
    for i in range(N):
        pattern = list(itertools.combinations(range(N), i + 1))
        result = calc(aaa, M, X, pattern)
        if result > 0:
            if tmp_result == 0:
                tmp_result = result
            else:
                tmp_result = min(tmp_result, result)

    if tmp_result != 0:
        return tmp_result
    else:
        return -1

N, M, X, *A = map(int, open(0).read().split())

aaa = []
aa = []
for index, x in enumerate(A):
    aa.append(x)
    if (index+1) % (M+1) == 0:
        aaa.append(aa)
        aa = []

print(solve(N, M, X, aaa))

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

keep=10**100
for i in range(0,2**n):
  rikai=[0]*m
  moji=""
  calc=i
  res=0
  for j in range(0,n):
    j=n-1-j
    onezero=calc//(2**j)
    moji+=str(onezero)
    calc-=onezero*(2**j)
  for k in range(0,n):
    if moji[k]=="1":
      res+=lis[k][0]
      for l in range(1,m+1):
        rikai[l-1]+=lis[k][l]
  prep=1
  for z in range(0,m):
    if rikai[z]<x:
      prep=0
  if prep==1:
    if res<keep:
      keep=res

      
if keep==10**100:
  print(-1)
else:
  print(keep)

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

c = []
d = []
for i in range(n):
	s = list(map(int, input().split()))
	d.append(s)
    
ans = 10**9
for i in range(1,n+1):
	for j in itertools.combinations(d,i):
		s = [0 for ii in range(m+1)]
		for k in j:
			for l in range(m+1):
				s[l] += k[l]
		y = min(s[1:])
		if y >= x:
			ans = min(ans,s[0])
            
if ans == 10**9:
	print (-1)
else:
	print (ans)

Solution (Python):
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 s in range(1 << n):
    money = 0
    understand = [0] * m
    for i in range(n):
        if (1 << i) & s != 0:
            money += c[i]
            for j in range(m):
                understand[j] += a[i][j]
    if min(understand) >= x:
        ans = min(ans, money)

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

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = MAX
    for n in range(1 << N):
        k = 0
        A = [0] * M
        for j in range(N):
            c, *alist = CA[j]
            if n >> j & 1:
                k += c
                for i in range(len(alist)):
                    A[i] += alist[i]
            if all([a >= X for a in A]):
                ret = min(ret, k)
                break
        else:
            continue

    print(-1 if ret == MAX else ret)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
import itertools
sys.setrecursionlimit(10**8)
INF = float("inf")


def bit(n, k):
    return (n >> k) & 1


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

    min_money = INF
    
    for pattern in itertools.product((0, 1), repeat=N):
        
        tot = [0]*M
        money = 0
        for i, use in enumerate(pattern):
            if use == 0:
                continue
            money += C[i]
            for j in range(M):
                tot[j] += A[i][j]

        if all(tot[j] >= X for j in range(M)):
            min_money = min(money, min_money)
    if min_money == INF:
        print(-1)
    else:
        print(min_money)

    return


if __name__ == '__main__':
    main()

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


ans = -1
for i in range(pow(2, N)):
    cost = 0
    flag = [False for _ in range(M)]
    rikai = [0 for _ in range(M)]
    binary = format(i, '0{}b'.format(N))
    for index, value in enumerate(binary):
        if value == '1':
            cost += Z[index][0]
            for j in range(1, M+1):
                rikai[j -1] += Z[index][j]
                if rikai[j -1] >= X:
                    flag[j -1] = True
        if all(flag):
            if ans == -1:
                ans = cost
                continue
            ans = min(ans, cost)
print(ans)

Solution (Python):
import itertools
import math
import fractions
import functools

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:])

minimum = 10**10
for i in range(2**n):
    cost = 0
    rikaido = [0]*m
    ok = True
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for index in range(m):
                rikaido[index] += a[j][index]
    for k in range(m):
        if rikaido[k] < x:
            ok = False
    if ok:
        minimum = min(minimum, cost)

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

Solution (Python):

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

Solution (Python):
import sys
sys.setrecursionlimit(100000000)




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

    res_money = 1_000_000_000_000
    for i in range(2 ** n):
        op = [0] * n  
        for j in range(n):
            if ((i >> j) & 1):
                op[n - 1 - j] = 1  
        s = [0] * m
        money = 0
        for k in range(n):
            if op[k] == 0:
                continue
            money += c[k]
            for l in range(m):
                s[l] += a[k][l]
        ng = False
        for p in range(m):
            if s[p] < x:
                ng = True
                break
        if not ng:
            if res_money > money:
                res_money = money

    if res_money != 1_000_000_000_000:
        print(res_money)
    else:
        print(-1)



main()

Solution (Python):
n,m,x=[int(j) for j in input().split()]
l=[]
import numpy as np
for i in range(n):
    tmp=[int(j) for j in input().split()]
    l.append((tmp[0],np.array(tmp[1:])))
ans=10**18
import itertools
for i in itertools.product(range(2),repeat=n):
    tl=np.array([0]*m)
    tc=0
    for idx,j in enumerate(i):
        if j==1:
            c,ll=l[idx]
            tc+=c
            tl+=ll
    if len(tl[tl>=x])==m:
        ans=min(ans,tc)

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

Solution (Python):
import sys
import numpy as np

def list_add(in1,in2):
    wrk = np.array(in1) + np.array(in2)
    return wrk.tolist()

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

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


for i in range(M):
    und_sum = 0
    for j in range(N):
        und_sum += book[j][i+1]
    if und_sum < X:
        print(-1)
        sys.exit()

min_money = 1000000000000000000
for i in range(2**N):
    if i == 0:
        continue
    flag_ok = 1
    buy = []
    for j in range(N):
        if((i>>j)&1):
            buy.append(j)
    sum = []
    for k in range(len(buy)):
        if k == 0:
            sum = book[buy[k]]
        else:
            sum = list_add(sum,book[buy[k]])
    for k in range(M):
        if sum[k+1] < X:
            flag_ok = 0
            break
    if flag_ok == 1:
        if min_money > sum[0]:
            min_money = sum[0]
    flag_ok = 1

print(min_money)

Solution (Python):
big_int = 10 ** 9

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

L = [0 for i in range(N)]
for i in range(N):
  L[i] = tuple(map(int, input().split()))

def foo(i):
  t = i
  T = [0 for j in range(M+1)]
  for j in range(N):
    for k in range(M+1):
      T[k] += L[j][k] * (t%2)
    t //= 2
  for k in range(1,M+1):
    if T[k] < X:
      return big_int
  return T[0]
  
ans = big_int

for i in range(2**N):
  ans = min(ans, foo(i))
  
if ans == big_int:
  print(-1)
else:
  print(ans)

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

C = []
A = []
for _ in range(n):
    tmp = list(map(int, input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])
    
f_inf = float("inf")    
ans = f_inf
for s in range(1<<n):
    cst = 0
    D = [0] * m
    for i in range(n):
        if s>>i & 1:
            cst += C[i]
            for j in range(m):
                D[j] += A[i][j]
    
    flg = True
    for d in D:
        if d < x: flg = False
    if flg: ans = min(ans, cst)

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

Solution (Python):
def ip():return list(map(int,input().split()))

n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    temp=ip()
    c.append(temp[0])
    a.append(temp[1:])

ans=12*10**5+1
for i in range(1,2**n):
    f=bin(i)[2:]
    sum=[0]*m
    while len(f)<n:f='0'+f
    s=0
    for j in range(n):
        if f[j]=='1':
            s+=c[j]
            for h in range(m):
                sum[h]+=a[j][h]
    if min(sum)>=x:ans=min(ans,s)
print(ans) if ans!=12*10**5+1 else print(-1)

Solution (Python):
from functools import reduce

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

mincost = 10**8

for i in range(2**n):
	case = [0] * (m+1)
	for j in range(n):
		if (i >> j) & 1:
			case = list(map(sum, zip(case, lb[j])))
	
	if reduce(lambda u, v: u and v, list(map(lambda y: y >= x, case[1:]))):
		mincost = min(mincost, case[0])

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

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

skill = [0] + [0] * m
ans = float("inf")
for i in range(2**n):
    i = format(i,"0{}b".format(n))
    for j in range(n):
        if str(i)[j] =="1":
            for l in range(m+1):
                skill[l] += list[j][l]
    money = skill.pop(0)
    if all(i>=x for i in skill):
        if ans>money:
            ans = money
    skill = [0] + [0] * m
if ans ==float("inf"):
    ans = -1
print(ans)

Solution (Python):
def ip():return list(map(int,input().split()))

n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    temp=ip()
    c.append(temp[0])
    a.append(temp[1:])

ans=12*10**5+1
for i in range(1,2**n):
    f=bin(i)[2:]
    sum=[0]*m
    while len(f)<n:f='0'+f
    s=0
    for j in range(n):
        if f[j]=='1':
            s+=c[j]
            for h in range(m):
                sum[h]+=a[j][h]
    F=True
    for h in range(m):
        if sum[h]<x:F=False
    if F==True:ans=min(ans,s)
print(ans) if ans!=12*10**5+1 else print(-1)

Solution (Python):
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]
c = [ca[i][0] for i in range(n)]
a = [ca[i][1:] for i in range(n)]
l = 0
ans = sum(c) 
for i in range(2 ** n):
    get = [0] * m
    kari = 0
    for j in range(n):
        if (i >> j) & 1: 
            get = [x + y for (x, y) in zip(get, a[j])]
            kari += c[j]
    
    
    if all([k >= x for k in get]):
        ans = min(ans,kari)
        l += 1
if l == 0:
    ans = -1
    
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m, x = map(int, input().split())
ca = [tuple(map(int, input().split()))for _ in range(n)]
INF = 10**18
ans = INF
proficiency = [0]*m


def dfs(i, cost):
    if i == n:
        global ans
        if cost < ans and all(x <= proficiency[j]for j in range(m)):
            ans = cost
        return 0
    c, *A = ca[i]
    for j in range(m):
        proficiency[j] += A[j]
    dfs(i+1, cost+c)
    for j in range(m):
        proficiency[j] -= A[j]

    dfs(i+1, cost)


dfs(0, 0)
print(ans if ans != INF else -1)