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())
CA = [tuple(map(int, input().split())) for _ in range(N)]

ans = None
for bit in range(1 << N):
    atotals = [0] * M
    ctotal = 0
    for i in range(N):
        if bit & (1 << i):
            ca = CA[i]
            for j, a in enumerate(ca[1:]):
                atotals[j] += a
            ctotal += ca[0]

    if all(map(lambda atotal: atotal >= X, atotals)):
        if ans is None:
            ans = ctotal
        else:
            ans = min(ans, ctotal)
if ans is None:
    print(-1)
else:
    print(ans)

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

ans=100000000000

for i in range(1, 2**N):
  price=0
  rikaido = [0]*M
  for j in range(N):
    if i>>j & 1:
      price += int(CAAA[j][0])
      for k in range(M):
        rikaido[k] += int(CAAA[j][k+1])
  for l in rikaido:
    if l < X:
      break
  else:
    ans = min(ans, price)
if ans == 100000000000:
  print(-1)
else:
  print(ans)

Solution (Python):


n,m,x=map(int,input().split())
A=[]
ALL=[]
ans=10**7
for i in range(n):
    A.append(list(map(int,input().split())))
for i in range(2**n):
    S=[0 for _ in range(m+1)]
    buy=[]
    for j in range(n):
        if ((i>>j) & 1):
            buy.append(A[j])
        
    for j in range(m+1):
        for k in range(len(buy)):
            S[j]+=buy[k][j]
    
    flag=0
    for j in range(1,m+1):
        if S[j]<x:
            flag=1
    if flag==0:
        ans=min(ans,S[0])
if ans==10**7:
    print(-1)
else:
    print(ans)

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

from itertools import product
import numpy as np

INF = 1001001001
ans = INF

for i in product(range(2), repeat=n): 
    tmp_price = 0
    tmp_und = np.zeros((m, ))
    for j in range(n):
        if i[j]:
            c, *a = ca[j]
            
            
            tmp_price += c
            tmp_und += np.array(a, dtype=np.int64)
    tmp_und = tmp_und.tolist()
    if all(tmp_und_ele >= x for tmp_und_ele in tmp_und):
        ans = min(ans, tmp_price)

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

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

ans=100000000000

for i in range(1, 2**N):
  price=0
  rikaido = [0]*M
  for j in range(N):
    if i>>j & 1:
      price += int(CAAA[j][0])
      for k in range(M):
        rikaido[k] += int(CAAA[j][k+1])
        for l in rikaido:
          if l < X:
            break
        else:
          ans = min(ans, price)
if ans == 100000000000:
  print(-1)
else:
  print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import numpy as np
    from itertools import product

    n, m, x = list(map(int, readline().split()))
    a, c = [], []
    for i in range(n):
        c_temp, *a_temp = list(map(int, readline().split()))
        c.append(c_temp)
        a.append(a_temp)

    a = np.array(a)
    ans = INF

    for bit in product(range(2), repeat=n):
        price_total = 0
        learn_total = np.array([0] * m)
        for i in range(n):
            if bit[i] == 1:
                price_total += c[i]
                learn_total += a[i]
        if np.all(learn_total >= x):
            ans = min(ans, price_total)

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


if __name__ == '__main__':
    main()

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

ans = 1000000000
for k in range(1, 2**N):
  price = 0
  rikaido=[0]*M
  for l in range(N):
    if k>>l & 1:
      
      price += int(CAAA[l][0])
      for t in range(M):
        rikaido[t] += int(CAAA[l][t+1])
        for r in rikaido:
          if r < X:
            break
        else:
          ans = min(ans, price)
if ans == 1000000000:
  print(-1)
else:
  print(ans)

Solution (Python):





if __name__ == "__main__":
    n, m, x = map(int, input().split())

    c = []
    a = []

    for _ in range(n):
        cost, *rikaido = map(int, input().split())
        c.append(cost)
        a.append(rikaido)

    INF = float("inf")
    ans = INF
    
    for bit in range(1 << n):
        price_total = 0
        learn_total = [0] * m

        for i in range(n):
            if (bit >> i) & 1:
                
                price_total += c[i]
                for j in range(m):
                    learn_total[j] += a[i][j] 
        
        
        judge = True
        for j in range(m):
            if learn_total[j] < x:
                judge = False
                break
        
        if judge:
            ans = min(ans, price_total)
        
    if ans == INF:
        print(-1)
    else:
        print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

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

def dfs(asum, b):
    global n, m, x
    rst = 10 ** 8
    if b == n:
        if all(asum[i] >= x for i in range(1, m + 1)):
            rst = asum[0]
    else:
        rst = min(rst, dfs(asum, b+1))
        asum2 = tuple(asum[i] + c[b][i] for i in range(m + 1))
        rst = min(rst, dfs(asum2, b+1))

    return rst

rst = dfs(tuple([0] * (m + 1)), 0)
ans = rst if rst < 10 ** 8 else -1
print(ans)

Solution (Python):
n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(n)
    mm = 0
    for j in range(len(s)):
        if s[j] == '1':
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)

Solution (Python):





import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string


BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def main():
    nmx=list(map(int,input().split()))
    n,m,x=nmx[0],nmx[1],nmx[2]
    nums=[]
    c=[]
    for i in range(n):
        temp=list(map(int,input().split()))
        c.append(temp[0])
        nums.append(temp[1:])
    
    
    combin=[]
    for i in range (1,n+1):
        combin.extend(list(itertools.combinations(range(n),i)))
    mn=[]
    for b in combin:
        temp,cost=[0]*m,0
        for y in b:
            for i in range(len(nums[y])):
                temp[i]+=nums[y][i]
            cost+=c[y]
        
        flag=True
        for j in range(m):
            if temp[j]<x:
                flag=False
                break
        if flag:
            mn.append(cost)
    
    print (min(mn) if len(mn)>0 else -1)
if __name__ == "__main__":
    main()

Solution (Python):
import itertools


def m():
    N, M, X = map(int, input().split())
    CA = [list(map(int, input().split())) for _ in range(N)]
    ans = float('inf')
    for i in itertools.product([True, False], repeat=N):
        tmp = [0] * (M + 1)
        for j, v in enumerate(i):
            if v:
                for k in range(M + 1):
                    tmp[k] += CA[j][k]
        f = 1
        for p in range(1, M + 1):
            if tmp[p] < X: f = 0
        if f: ans = min(ans, tmp[0])
    return ans if ans != float('inf') else "-1"


print(m())

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)

min_prices = 10**9
for i in range(1 << N):
    prices = 0
    rikaido = [0] * M
    for j in range(N): 
        if ((i >> j) & 1) == 1: 
            prices += c[j]
            for k in range(M):
                rikaido[k] += a[j][k]
        if all(l>=X for l in rikaido):
            min_prices = min(min_prices,prices)
print(min_prices if min_prices != 10**9 else -1)

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

minimum = float("inf")
for i in range(2**n):
    select = [0] * n
    a = [0] * m
    money = 0
    for j in range(n):
        if (i>>j)&1:
            select[n-1-j] = 1
    for i, v in enumerate(select):
        if v == 1:
            money += CA[i][0]
            for j, u in enumerate(CA[i][1:]):
                a[j] += u
    if not len([l for l in a if l < x]):
        minimum = min(minimum, money)
print(-1 if minimum == float("inf") else minimum)

Solution (Python):
import numpy as np
N, M, X = map(int, input().split())
C = []
A = np.zeros((N, M), dtype=int)
for i in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A[i] = a

S = np.sum(A, axis=0)
if True in (S < X):
    print(-1)
    exit(0)

C_ = []
for i in range(2**N):
    total = 0
    arr = np.zeros((M,),dtype=int)
    for j in range(N):
        if ((i>>j) & 1) == 1:
            total += C[j]
            arr += A[j]
    if True in (arr < X):
        continue
    C_.append(total)
print(min(C_))

Solution (Python):

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

ls = []
costmin = 10**18
for i in range(n):
  ls.append(list(map(int,input().split())))

for i in range(2**n+1):
  cost = 0
  
  
  f = "{{:0{}b}}".format(n)
  now = f.format(i)
  understand = [0]*m
  for j in range(len(now)):
    if now[j] == "1":
      cost += ls[j][0]
      for k in range(m):
        understand[k] += ls[j][k+1]
  
  if min(understand) >= x:
    money.append(cost)
if len(money) == 0:
  print(-1)
else:
  money.sort()
  print(money[0])

Solution (Python):



import sys

def main():
    N, M, X = map(int, input().split())
    S = [list(map(int,input().split())) for i in range(N)]
    ret = 10**7
    for i in range(2 ** N):
        TA = [0] * M
        TC = 0
        for j in range(N):    
            if (i >> j) & 1:  
                TC += S[j][0]
                for m in range(M):
                    TA[m]+=S[j][m+1]  
        if min(TA)>=X:
            ret = min(ret, TC)
    if ret == 10**7:
        print(-1)
    else:
        print(ret)

if __name__ == '__main__':
    main()

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

    
    


    


INF = float('inf')

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









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



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

Solution (Python):
from itertools import product

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

for _ in range(n):
    c, *mi = map(int, input().split())
    C.append(c)
    M.append(mi)

sta = list(product((0, 1), repeat=n))
res = 10**10

for k in sta:
    tmp = 0
    cnt = [0] * m
    for j in range(n):
        if k[j] == 1:
            tmp += C[j]
            for l in range(m):
                cnt[l] += M[j][l]
    if min(cnt) >= x:
        res = min(res, tmp)

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

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

C=10**7
for i in range(2**N):
  P,T=[0]*M,0
  for j in range(N):
    if i&2**j:
      T+=A[j][0]
      for k in range(M):
        P[k]+=A[j][k+1]
  for j in range(M):
    if P[j]<X:
      break
  else:
    C=min(C,T)

print(-1 if C==10**7 else C)

Solution (Python):
import itertools

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

ans=float('inf')

def j(q):
    tmp=0
    cnt=[0]*m
    for i in range(n):
        if q[i]==1:
            tmp+=c[i]
            for j in range(m):
                cnt[j]+=a[i][j]
    if min(cnt)>=x:
        return tmp
    return 0

for tk in itertools.product([0,1],repeat=n):
    h=list(tk)
    ff=j(h)
    if ff!=0:
        ans=min(ans,ff)
if ans==float('inf'):
    print(-1)
    exit()
print(ans)

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

minimum = float("inf")
for i in range(2**n):
    select = [0] * n
    a = [0] * m
    money = 0
    for j in range(n):
        if (i>>j)&1:
            select[n-1-j] = 1
    for i, v in enumerate(select):
        if v == 1:
            money += CA[i][0]
            for j, u in enumerate(CA[i][1:]):
                a[j] += u
    if all(l >= x for l in a):
        minimum = min(minimum, money)
print(-1 if minimum == float("inf") else minimum)

Solution (Python):
n, m, x = map(int,input().split(' '))
a = [[] for i in range(n)]
p = 0
for i in range(n):
    a[i] = list(map(int, input().split(' ')))
sc = 12 * 100001
for i in range(1, 2 ** n):
    bi = '0' * n + bin(i)[2:]
    bi = bi[len(bi) - n:]
    cc = 0
    e = [0] * m
    for j in range(n):
        if bi[j] == '1':
            for k in range(m):
                e[k] += a[j][k + 1]
            cc += a[j][0]
    su =True
    for j in range(m):
        su &= e[j] >= x
    if su:
        sc = min(sc, cc)
sc = -1 if sc > 12 * 100000 else sc
print(sc)

Solution (Python):
def getls():
    return [ipt for ipt in input().split()]
def getlsi():
    return [int(ipt) for ipt in input().split()]
[n,m,x] = getlsi()
ls = []
cs = []
for i in range(n):
    tmp = getlsi()
    cs.append(tmp[0])
    ls.append(tmp[1:])
xs = [x] * m
for i in range(n):
    for j in range(m):
        xs[j] -= ls[i][j]
if len([k for k in xs if k > 0]) > 0:
    print(-1)
else:
    cost = 10 ** 5 * 13
    for i in range(1,2 ** n):
        tmp_cost = 0
        tmp_ls = [0] * m
        tmp = "{:0"+str(n)+"b}"
        tmp = tmp.format(i)
        for j in range(n):
            if tmp[j] == "1":
                for k in range(m):
                    tmp_ls[k] += ls[j][k]
                tmp_cost += cs[j]

        if min(tmp_ls) >= x and tmp_cost < cost:
            cost = tmp_cost
    print(cost)

Solution (Python):
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 1000000007



n, m, x = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for j in range(n)]












min = 1200001
for i in range (2 ** n):
    flag = 1
    for k in range(1,m+1):
        temp = 0
        cost = 0
        for l in range(0,n):
            mask = 1 << l
            if (i & mask):
                temp += table[l][k]
                cost += table[l][0]
        if (temp < x) :
            flag = 0
    if(flag == 1 and min > cost):
        min = cost


if (min == 1200001):
    print("-1")
else:
    print(min)

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

ans = 10**9
for i in range(2**n):
	cnt = 0
	b = [0 for i in range(m)]
	for j in range(n):
		if (i >> j) & 1:
			cnt += c[j]
			for k in range(m):
				b[k] += a[j][k]
	mn = min(b)
	if mn >= x:
		ans = min(ans,cnt)
if ans == 10**9:
	print (-1)
else:
	print (ans)

Solution (Python):
N,M,X = map(int, input().split())
CA_array = list()
for i in range(N):
    CA_list = [int(e) for e in input().split()]
    CA_array.append(CA_list)
    
ans = 13*(10**5)
    

for i in range(2**(N)): 
    bit_array = str(bin(i)[2:]).zfill((N))
    

    CA_on_bit_array = [0 for _ in range(M+1)]
    
    for j in range(len(bit_array)): 

        if bit_array[j]=="0":
            
            pass
        elif bit_array[j]=="1":
            
            for k in range(M+1): 
                CA_on_bit_array[k] += CA_array[j][k]

    
    for k in range(1,M+1):
        if CA_on_bit_array[k] < X:
            break
    else:
        if CA_on_bit_array[0] < ans:
            ans = CA_on_bit_array[0]

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

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

a = 1 <<(n )
r = []
for i in range(a):
    li = np.array([0 for _ in range(m +1)])
    for j in range(n):
        if i & (1 << j):
            li += l[j]

    for k in range(1,m +1):
        if li[k] < x:
            break
        if k == m:
            r +=[li[0]]
        
if len(r) == 0:
    print('-1')
else:
    print(min(r))

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


for i in range(2**n):  
    price = 0
    point = [0]*m
    for j in range(n):
        if(i >> j) & 1 == 1: 
            price += listA[j][0]
            for k in range(m):
                point[k] += listA[j][k+1]
    if min(point) >= x:
        ans = min(ans, price) if ans != -1 else price

print(ans)

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

ans=float('inf')
for mask in range(1<<n):
    tmp=[0]*m
    cost=0
    for i in range(n):
        if (mask>>i)&1:
            cost+=c[i]
            for j in range(m):
                tmp[j]+=a[i][j]
    flag=True
    for i in range(m):
        if tmp[i]<x:
            flag=False
            break
    if flag:
        ans=min(ans,cost)
print(ans) if ans!=float('inf') else print(-1)

Solution (Python):
import itertools

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

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

min = float('inf')
for i in range(n + 1):
  for com in list(itertools.combinations(a, i)):
    cost = 0
    skill = [0] * m
    for l in com:
      cost += c[a.index(l)]
      for mi in range(m):
        skill[mi] += l[mi]

    ans = True
    for sm in skill:
      ans = sm >= x and ans

    if ans and min > cost:
      min = cost

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

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


cc_ = []
for i in range(n):
    cc_.append(c_[i][0])


import numpy as np
import itertools
l_ = np.arange(n).tolist()

res_ = []
resList = []
flag = False
flag3 = True
if n == 1:
    for i in range(m):
        if c_[0][i+1] < x:
            
            flag3 = False
    print(cc_[0] if flag3 else -1)
else:
    for i in range(1,n+1):
        c = list(itertools.combinations(l_, i))
        for j in c:
            res_ = []
            flag2 = True
            for l in range(m):
                res = 0
                sum_money = 0
                for k in range(len(j)):
                    res += c_[j[k]][l+1]
                    sum_money += c_[j[k]][0]
                
                if res < x:
                    flag2 = False
            if flag2:
                resList.append(sum_money)
                flag = True
    
    print(min(resList) if flag else -1)

Solution (Python):


import sys
read = sys.stdin.buffer.read 
readline = sys.stdin.buffer.readline 
readlines = sys.stdin.buffer.readlines 
sys.setrecursionlimit(10**7) 

"""

n = readline().rstrip() 
lis = readline().rstrip().split() 


n = int(readline().rstrip()) 
a, b, c = map(int,readline().rstrip().split()) 
A = list(map(int,readline().rstrip().split()))  
lis = [readline().rstrip().split() for _ in range(n)] 


s_lis=[readline().rstrip().decode() for _ in range(n)] 

s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]

s_lis=[readline().rstrip().split().decode() for _ in range(n)] 


s_lis=[int(readline().rstrip()) for _ in range(n)] 

s_lis=[int(readline().rstrip().split()) for _ in range(n)]


s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""


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

costs = []
for i in range(2 ** n):
    flag = True
    cost = 0
    algos = [0] * m 
    op = [False] * n 
    for j in range(n):
        if ((i >> j) & 1): 
            op[n - j - 1] = True 
    

    for j in range(n):
        if op[j]: 
            
            for ind, el in enumerate(ca[j][1:]): 
                algos[ind] += el
            cost += ca[j][0]
            
    for j in algos:
        if j < x:
            flag = False
    if flag:
        costs.append(cost)

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

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

bit = (list(itertools.product([0,1], repeat=n)))

d=[]
for i in range(len(bit)):
    kounyuu = []
    nedan=[]
    for j in range(n):
        if bit[i][j]==1:
            kounyuu.append(a[j])
            
            c=[]
            for k in range(1,m+1):
                b = []
                for z in range(len(kounyuu)):
                    b.append(kounyuu[z][k])
                if(sum(b))>=x:
                    c.append(sum(b))
            if len(c)==m:
                for z in range(len(kounyuu)):
                    nedan.append(kounyuu[z][0])
                d.append(sum(nedan))
if d == []:
    print(-1)
else:
    print(min(d))

Solution (Python):
import itertools
n,m,k=map(int,input().split())
l=[[int(i) for i in input().split()] for l in range(n)]
min_price=10**8
min_list=[]
a=itertools.product([True,False],repeat=n)
for x in a:
    li=[0]*(m+1)
    for i,y in enumerate(x):
        if y:
            for z in range(m+1):
                li[z]+=l[i][z]
    if min_price>li[0]:
        f=True
        for o in li[1:]:
            if o<k:f=False
        if f:min_price=li[0]
print(min_price if min_price!=10**8 else -1)

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


def cal_score(bought_books):
    global CA
    global M
    global N
    global X
    algo_Q = [0]*M
    cost = 0
    for i in range(N):
        if bought_books[i] == 1:
            for j in range(1, M+1):
                algo_Q[j-1] += CA[i][j]
            cost += CA[i][0]
    flag = True
    for i in range(M):
        if algo_Q[i] < X:
            flag = False
            break
    if flag:
        global min_can
        min_can.add(cost)
    return 0


def next_book(book_list):
    global N
    global M

    if len(book_list) == N:
       return cal_score(book_list)
    book_list.append(0)
    next_book(book_list)
    book_list.pop(-1)

    book_list.append(1)
    next_book(book_list)
    book_list.pop(-1)
    return 0


book_list = []
next_book(book_list)
if set() == min_can:
    print(-1)
else:
    print(min(min_can))

Solution (Python):
def solve():
    N, M, X = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    ans = 10**9
    for b in range(1<<N):
        cost = 0
        for i in range(N):
            if b>>i&1:
                cost += A[i][0]
        for j in range(M):
            cnt = 0
            for i in range(N):
                if b>>i&1:
                    cnt += A[i][j+1]
            if cnt<X:
                break
        else:
            ans = min(ans,cost)
    if ans==10**9:
        return -1
    return ans
print(solve())

Solution (Python):
n,m,x=map(int,input().split())
data=[]
for i in range (n):
  a=list(map(int,input().split()))
  data.append(a)
mIN=10**7
for i in range(2**n):
  money=0
  bag=[]
  rikai=[0]*m
  cnt=[0]*m
  for j in range(n):
    if (i>>j)&1 :
      bag.append(data[j])
  for k in bag:
      money+=k[0]
      for s in range(m):
        rikai[s]+=k[s+1]
        if rikai[s]>=x:
          cnt[s]+=1
  if cnt.count(0)==0:
    mIN=min(mIN,money)
    
if mIN==10**7:
  print("-1")
else:
  print(mIN)

Solution (Python):
n, m, x = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 193934993409409
for mask in range(2 ** n):
    C = [0] * m
    cst = 0
    for i in range(n):
        if (mask >> i) & 1:
            cst += X[i][0]
            for j in range(1, m + 1):
                C[j - 1] += X[i][j]
    if min(C) >= x:
        ans = min(ans, cst)
if ans < 91912922191:
    print(ans)
else:
    print(-1)

Solution (Python):
import numpy as np


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

cnt = (10 ** 5) * N + 1

for i in range(2 ** N):
    score = np.zeros(M + 1)
    for j in range(N):
        if (i >> j) & 1:
            score += CA[j]
    for k in range(1, M + 1):
        if score[k] < X:
            break
    else:
        if score[0] < cnt:
            cnt = score[0]
            
if cnt != (10 ** 5) * N + 1:
    print(int(cnt))
else:
    print(-1)

Solution (Python):



from itertools import product

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

INF = 1000000000000000000000000000
ans = INF


lists = list(product(list(range(2)), repeat = n))
for v in lists:
    '''
    for i in range(1<<n):  
        
    '''
    c = 0
    sums = [0]*m
    for j in range(n):
        if v[j]==1:        
            '''
            if i>>j & 1: 
            '''
            
            c += costs[j][0]
            for k in range(m):
                sums[k] += costs[j][k+1]    
                
                
    if min(sums) >= x: 
        ans = min(ans, c)                
    '''
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)
    でもよい。
    '''
    
        
if ans==INF:
    print(-1)
else:
    print(ans)

Solution (Python):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    import numpy as np
    N, M, X = map(int, input().split())
    C = [0] * N
    A = np.zeros((N, M), int)
    for i in range(N):
        B = list(map(int, input().split()))
        C[i] = B[0]
        for j in range(1, M+1):
            A[i, j-1] = B[j]

    
    
    answer = pow(10, 9)
    import itertools

    L = itertools.product([True, False], repeat = N)

    for l in L:
        skill = np.zeros(M, int)
        temp_answer = 0
        for i in range(N):
            if l[i]:
                skill += A[i]
                temp_answer += C[i]
        if np.all(skill >= X):
            answer = min(temp_answer, answer)
    if answer != pow(10, 9):
        print(answer)
    else:
        print(-1)

if __name__ == "__main__":
    main()

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

A=[0]*n
c=[0]*n

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

for i in range(n):
    c[i]= A[i][0]
    A[i] = A[i][1:]

import numpy as np
import sys

a = np.array(A)

ans = np.inf

for s in range(1<<n):
    cost = 0
    d = np.array([0]*m)
    for i in range(n):
        if s>>i&1:
            cost += c[i]
            d += a[i]
    if all(d >= x):
        ans = min(ans,cost)

print(ans if ans != np.inf else '-1')

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

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

for i in range(n):
    a = [int(i) for i in input().split()]
    costs.append(a)
'''


INF = 1000000000000000000000000000
ans = INF

for i in range(1<<n):  
    
    c = 0
    sums = [0]*m
    for j in range(n):
        if i>>j & 1: 
            
            c += costs[j][0]
            for k in range(m):
                sums[k] += costs[j][k+1]    
    '''
    cost = 0
    c = 0
    sums = [0] * m
    use_index=[]
    for j in range(n):
        if i%2==1:
            use_index.append(j)
        i >>= 1
    
    for v in use_index:
        c += costs[v][0]        
        for j in range(m):
            sums[j] += costs[v][j+1]
    '''
    
    
    if all(s>=x for s in sums):
        ans = min(ans, c)
'''            
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)
'''
if ans==INF:
    print(-1)
else:
    print(ans)