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



Sample input:
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9


Sample output:
120

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
book = [list(map(int, input().split())) for i in range(N)]
out = 10**12
for i in range(0, 2**N):
    list = [0] * (M+1)
    st = format(int(i), "b").zfill(N)
    for j in range(N):
        if int(st[j]) == 1:
            for a in range(M+1):
                list[a] +=  book[j][a]
            
    if all([b >= X for b in list[1:]]) == True:
        out = min(out, list[0])

if out == 10**12:
    print(-1)

else:
    print(out)

Submission status: Accepted

Solution code:
import math
import numpy as np

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n,m,x = NextInts()
data = np.array([NextIntList() for i in range(n)], np.int64)

c = data[:,:1].reshape(n)
a = data[:,1:]
ans = 10**10

for i in range(1<<n): 
    now = 1
    point = np.zeros(m, np.int64)
    tmp = 0
    for j in range(n):
        if now&i:
            for k in range(m):
                point[k] += a[j][k]
            tmp += c[j]
        now <<= 1
    ju = True
    for i in range(m):
        if point[i] < x:
            ju = False
            break
    if ju:
        ans = min(ans, tmp)
if ans == 10**10: print(-1)
else: print(ans)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
D = [list(map(int, input().split())) for i in range(N)]
money = 12 * 10 ** 5 + 1
for i in range(2**N):
    pattern = str(bin(i))[2:]
    und = [0] * M
    mon = 0
    for j in range(len(pattern)):
        if pattern[(-1)*j - 1] == '1':
            mon += D[j][0]
            for k in range(M):
                und[k] += D[j][k + 1]
    for k in range(M):
        if all([l >= X for l in und]):
            money = min(mon, money)
if money == 12 * 10 ** 5 + 1:
    money = -1
print(money)

Submission status: Accepted

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

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

INF = 10**9
ans = INF
    
for s in range(0, 1<<n):
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if (s>>i) % 2 == 0: 
            continue
        cost_sum += c[i]
        for j in range(m):
            smart[j] += A[i][j]
    ok = True
    for j in range(m):
        if smart[j] < X:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

if ans == INF:
    ans = -1

print(ans)

Submission status: Accepted

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

total = 0
result = 10000000000000000
count = 0
flag = True

#print(c_A)
for i in range(2 ** N):
    total = 0
    count = 0
    bit = [0]*N
    for j in range(N):
        state = [0] * M
        if (i >> j) & 1:
            bit[j] = 1
    
    #1の時全てのANを足し合わせる。合計金額を出す
    for k in range(N):
        if bit[k] == 1:
            #print(bit)
            for l in range(M):
                state[l] += c_A[k][l+1]
            total += c_A[k][0]
    #print(state)
    #print()
    #X以上じゃなければbreak
    for m in range(M):
        if state[m] < X:
            break
        else:
            count += 1
    #print(count)
    if count == M:
        flag = False
        result = min(total,result)
if flag == False:
    print(result)
else:
    print(-1)

Submission status: Accepted

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

min_ = 10**8

costs = []
effects = []

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

for i in range(2**n):
  now_cost = 0
  now_effects = [0]*m
  for j in range(n):  # このループが一番のポイント
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      for k in range(m):
        now_effects[k] += effects[j][k]
      now_cost += costs[j]

  ok=True    
  for k in range(m):
    if now_effects[k] < x:
      ok=False
      break
  if ok:
    min_ = min(min_,now_cost)

if min_ == 10**8:
  print(-1)
  exit()
print(min_)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
book_lists = [list(map(int, input().split())) for i in range(N)]
max_cost = 10**5*12+1
min_cost = max_cost

for i in range(1, 2**N):
    score_list = [0 for _ in range(M)]
    cost = 0
    for j in range(N):
        if i >> j & 1:
            cost += book_lists[j][0]
            for k in range(M):
                score_list[k] += book_lists[j][k+1]
    if min(score_list) >= X:
        min_cost = min(cost, min_cost)

print(min_cost if not min_cost == max_cost else -1)

Submission status: Accepted

Solution code:
from sys import stdin, stdout
from collections import deque, defaultdict

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	s = mask
	while s > 0:
		process(s)
		s = (s-1) & mask

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from sys import stdin, stdout

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	s = mask
	while s > 0:
		process(s)
		s = (s-1) & mask

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from sys import stdin, stdout

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def submasks(m):
	s = m
	while s > 0:
		s = (s-1)&m
		yield s

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	for s in submasks(mask):
		process(s)

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

bit_matrix = itertools.product(range(2), repeat = N)

arr_book_matrix = np.array(book_matrix)
arr_bit_matrix = np.array(list(bit_matrix))

arr_ans_matrix = np.dot(arr_bit_matrix, arr_book_matrix)

ans_matrix = arr_ans_matrix.tolist()

ans = 100000 * 20
for ans_vector in ans_matrix:
    if(min(ans_vector[1:]) >= X):
        ans = min(ans, ans_vector[0])

if(ans == 100000 * 20):
    print(-1)

else:
    print(ans)

Submission status: Accepted

Solution code:
def function():
    N,M,X = map(int, input().split())
    maxCost=0
    Aij = []
    for n in range(0,N):
        Aj = list(map(int, input().split()))
        maxCost += Aj[0]
        Aij.append(Aj)

    maxCost += 1
    minCost = maxCost
    total = pow(2, N)
    for n in range(1,total):
        x = [0]*M
        cost = 0
        i = 0
        while n>>i != 0:
            if (n>>i) & 1 == 1:
                Aj = Aij[i]
                cost += Aj[0]
                for j in range(1,len(Aj)):
                    x[j-1] += Aj[j]
            i += 1
        
        # check his understanding is higher than X
        higher = True
        for xv in x:
            if xv < X:
                higher = False
                break
        if higher == True:
            minCost = min(cost, minCost)
    if minCost == maxCost:
        minCost = -1
    print(minCost)

if __name__ == '__main__':
    function()

Submission status: Accepted

Solution code:
# 初期入力
from itertools import combinations
from itertools import product
import numpy as np 
import sys
input   = sys.stdin.readline
N,M,X   = (int(x) for x in input().split())
C       = [list(map(int, input().split())) for i in range(N)]
all_book= [i for i in range(N)]          #買う本

price_list  =[]
flag        =False
C_np        =np.array(C,dtype=int)
price       =C_np[:,0]
understand  =np.delete(C_np,0,1)

for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy         =np.array(t,dtype=int)      #今回買った本
        understand_now   =understand[book_buy]       #買ったうちの各本の知識
        understand_sum   =np.sum(understand_now,axis=0) #知識の合計

        if np.all(X <= understand_sum ): #アルゴリズム理解度が全て目標値X以上か
            price_now =price[book_buy]
            price_list.append(np.sum(price_now))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        #買う本
N, M, X = map(int, input().split())
C_np    = np.array([list(map(int, input().split())) for _ in range(N)], dtype=int)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]
#C_np        =np.array(C,dtype=int)
price       =C_np[:,0]
understand  =np.delete(C_np,0,1)
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = understand[book_buy] 
        understand_sum  = np.sum(understand_now, axis=0)
        if np.all(understand_sum >= X):
            price_now =price[book_buy]
            price_list.append(np.sum(price_now))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        #買う本
N, M, X = map(int, input().split())
C_np    = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]
#C_np        =np.array(C,dtype=int)
price       =C_np[:,0]
understand  =np.delete(C_np,0,1)
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = understand[book_buy] 
        understand_sum  = np.sum(understand_now, axis=0)
        if np.all(understand_sum >= X):
            price_now =price[book_buy]
            price_list.append(np.sum(price_now))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        #買う本
N, M, X = map(int, input().split())
items   = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            price_list.append(np.sum(tmp[0]))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np
        #買う本
N, M, X = map(int, input().split())
items   = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out     = 10**18
flag    =False
price_list  =[]
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            #out = min(out, tmp[0])
            price_list.append(np.sum(tmp[0]))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

N, M, X = map(int, input().split())
pricelist = [0] * N
matrix = [[0] * M for _ in range(N)]
for i in range(N):
    row = list(map(int, input().split()))
    pricelist[i] = row.pop(0)
    matrix[i] = row

mintotalprice = 10**5 * 12 + 1
for bit in range(2**N):
    flag = True
    for j in range(M):
        totalscore = 0
        for i in range(N):
            if (bit>>i & 1) == 1:
                totalscore += matrix[i][j]
        if totalscore < X:
            flag = False
            break
    if flag:
        totalprice = 0
        for i in range(N):
            if (bit>>i & 1) == 1:
                totalprice += pricelist[i]
        mintotalprice = totalprice if mintotalprice > totalprice else mintotalprice
        
print(mintotalprice if mintotalprice != 10**5 * 12 + 1 else -1)

Submission status: Accepted

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

p = []

for i in range(1, 2**N):
    buff = [0] * (M + 1)

    for j in range(N):
        if i >> j & 1:
            buff = [a + b for a, b in zip(buff, books[j])]

    for a in buff[1:]:
        if a < X:
            break
    else:
        p.append(buff[0])

if len(p) > 0:
    ans = min(p)
else:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np
        #買う本
N, M, X = map(int, input().split())
items   = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out     = 10**18
flag    =False
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            out = min(out, tmp[0])
            flag =True
if flag ==True:
    print(out)
else:
    print(-1)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np
        #買う本
N, M, X = map(int, input().split())
items = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out = 10**18
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            out = min(out, tmp[0])

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

Submission status: Accepted

Solution code:
n,m,x=(int(i) for i in input().split())
a=[]
c=[]
for i in range(n):
  a.append(list(map(int,input().split())))
  c.append(a[i][0])
  del a[i][0]
  
INF=1001001001
ans=INF

for s in range(1<<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==INF:
  print(-1)
else:
  print(ans)

Submission status: Accepted

Solution code:
N_satsu, M_ko, X = map(int, input().split())

Books = []
min_money = float('inf')

for i in range(N_satsu):
    tmp = list(map(int, input().split()))
    Books.append(tmp)


for i in range(2 ** N_satsu):
    sum_money = 0
    sum_skill = [0 for k in range(M_ko)]
    
    for j in range(N_satsu):
        bitt = i >> j
        if (bitt & 1):
            sum_money += Books[j][0]
            
            for _ in range(M_ko):
                sum_skill[_] += Books[j][_ + 1]
    
    judge = [l >= X for l in sum_skill]
    if (all(judge)):
        min_money = min(min_money, sum_money)

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

Submission status: Accepted

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

result = []

for n in range(1,len(a)+1):
    for conb in itertools.combinations(a, n):
        result.append(np.array(conb)) #タプルをリスト型に変換

count = 0

ans = []

for i in range(len(result)):
    t = sum(result[i])
    # print(t)
    for k in range(1,len(t)):
        # print(t[k])
        if t[k] >= x:
            count += 1
        else:
            count = 0
            break
    if count == m:
        ans.append(t[0])
        count = 0
        
    
if len(ans) > 0:
    # print(ans)
    
    print(min(ans))
    
else:
    print(-1)

Submission status: Accepted

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

A = [[] for _ in range(n)]
c = [0] * n

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

INF = 10**9
ans = INF

for s in range(0,1 << n): #2進数
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if (s >> i) % 2 == 0: continue
        cost_sum += c[i]
        for j in range(m):
            smart[j] += A[i][j]
    ok = True
    for j in range(m):
        if smart[j] < x:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

if ans == INF:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
n, m, x = list(map(int, input().split()))
cl = []
al = []

for i in range(n):
    c = input()
    a = []
    asum = 0
    for i, d in enumerate(c.split()):
        if i == 0:
            cl.append(int(d))
        else:
            a.append(int(d))
            # asum += int(d)
    al.append(a)


def filter(l, x):
    for e in l:
        if int(e) < x:
            return False
    return True


ok_price_list = []

for i in range(2**n):
    f = '0%db' % n
    si = format(i, f)
    price = [int(x) * int(y) for (x, y) in zip(si, cl)]
    point_sum = [0 for m in range(n)]
    for j, sb in enumerate(si):
        if sb == '1':
            point_sum = [x+y for (x, y) in zip(point_sum, al[j])]
    if filter(point_sum, x):
        ok_price_list.append(sum(price))
if len(ok_price_list) > 0:
    print(sorted(ok_price_list)[0])
else:
    print(-1)

Submission status: Accepted

Solution code:
def task(n, m, x, c, a):
    mx = [0] * m
    for i in range(0, n):
        for j in range(0, m):
            mx[j] += a[i][j]

    for j in range(0, m):
        if mx[j] < x:
            print(-1)
            return

    states = [0] * m

    best = 100000000
    for i in range(1, 2**n):
        price = 0

        for k in range(0, m):
            states[k] = 0

        for j in range(0, n):
            if ((i >> j) & 1):
                price += c[j]
                for k in range(0, m):
                    states[k] += a[j][k]

        if price < best:
            found = True
            for k in range(0, m):
                if states[k] < x:
                    found = False
                    break

            if found:
                best = price

    print(best)


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

task(n, m, x, c, a)

Submission status: Accepted

Solution code:
import numpy as np
import itertools
n,m,x=map(int,input().split())
a=[]
b=[0]*m
skill=np.array([b])
ans=[]
money=0
for _ in range(n):
    a.append(list(map(int,input().split())))
for i in range(1,n+1):
    for j in itertools.combinations(range(1,n+1),i):
        for k in range(len(j)):
            money+=a[j[k]-1][0]
            skill+=np.array([a[j[k]-1][1:m+1]])
        if all([i>=x for i in skill[0]]):
            ans.append(money)
        money=0
        skill=np.array([b])
if len(ans)==0:
    print(-1)
else:
    print(min(ans))

Submission status: Accepted

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

def makeTableA(dat,n,m):
    tbl=[[0]*m]*n
    #print(n,len(tbl),m,len(tbl[0]))
    for i in range(n):
        tup=dat[i]
        a=tup[1]
        #print(a)
        #for j in range(m):
        #    tbl[i][j]=a[j]
        tbl[i]=list(a) 
        #print(tbl) 
    return tbl  


def main(n,m,x,dat):
    tblA=makeTableA(dat,n,m)
    #print(tblA)
    tblB=[[0]*(m+2)]*2**n  #
    #print(n,m,len(tblB), len(tblB[0]))  
    for i in range(2**n):
        tblB[i]=[0]*(m+2)
        b=1
        for j in range(n):
            if(i&b==b):
                for k in range(m):
                    #print(j,k)
                    tblB[i][k]+=tblA[j][k]
                    #print(tblB)
                tblB[i][m]+=dat[j][0]
                #print(tblB)
            b=b*2
        tblB[i][m+1]=min(tblB[i][0:m])
        #print(tblB)
    #print(tblB)
    # テーブルをスキャンする
    Pmin=12*10**5+1
    for i in range(2**n):
        if(tblB[i][m+1]>=x):
            price=tblB[i][m]
            if(price < Pmin):
                Pmin=price
    if(Pmin==12*10**5+1):
        Pmin=-1
    return Pmin


def readinput2():
    n,m,x = list(map(int,input().split()))
    tblA=[]
    c=[]
    for i in range(n):
        s=list(map(int,input().split()))
        c.append(s[0])
        tblA.append(s[1:])
    #print(c,tblA)
    return n,m,x,c,tblA

def main2(n,m,x,c,a):
    tblB = [[0 for j in range(m+2)] for i in range(2**n)]
    for i in range(2**n):
        nn=1
        for j in range(n):
            #print(i,nn)
            if (i&nn==nn):
                for k in range(m):
                    tblB[i][k]+=a[j][k]
                tblB[i][m]+=c[j]
            nn=nn*2
        tblB[i][m+1]=min(tblB[i][:m])
        #print(tblB)

    Pmin=12*10**5+1
    for i in range(2**n):
        if(tblB[i][m+1]>=x):
            price=tblB[i][m]
            if(price < Pmin):
                Pmin=price
    if(Pmin==12*10**5+1):
        Pmin=-1
    return Pmin


if __name__=='__main__':
    #n,m,x,dat=readinput()
    #ans=main(n,m,x,dat)
    n,m,x,c,tblA=readinput2()
    ans=main2(n,m,x,c,tblA)
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

N, M, X, B = *map(int, input().split()), np.array([])

class book:
    def __init__(self, price, *understanding):
        self.price = price
        self.understanding = np.array(understanding)
    def __add__(self, other):
        return book(self.price+other.price , *self.understanding+other.understanding)

for _ in range(N):
    B = np.append(B, book(*map(int, input().split())))

P = []
for i in range(2**N):
    temp = book(0, *[0]*M)
    for j in range(N):
        if ((i >> j) & 1):
            temp += B[j]
    P.append(temp)

P = np.array(list(filter(lambda x: all(X<=x.understanding),P)))
P = np.array(list(sorted(P, key=lambda x: x.price)))
try:
    print(P[0].price)
except IndexError:
    print(-1)

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
l=[]
c=[]
l4=[]
for _ in range(n):
    k=list(map(int,input().split()))
    c.append(k[0])
    l.append(k[1:])

for i in range(2**n):
    l2=[]
    for j in range(n):
        if (i>>j)&1==1:
            l2.append(j)
    l3=[0]*m
    for jj in l2:
        for kk in range(m):
            l3[kk]+=l[jj][kk]
    if min(l3)>=x:
        count=0
        for kkk in l2:
            count+=c[kkk]
        l4.append(count)
if l4==[]:
    print(-1)
else:
    print(min(l4))

Submission status: Accepted

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

def calc_cost(book, next_book):
  result = []
  for i, a in enumerate(next_book):
    result.append(book[i] + a) 
  return result

def search_cost(num, sum_book):
  if num >= n:
    for a in sum_book[1:]:
      if a < x:
        return
    ans_cost.append(sum_book[0])
    return
  next_book = calc_cost(sum_book, books[num])
  num += 1
  search_cost(num, next_book)
  search_cost(num, sum_book)

empty_book = [0 for _ in range(m+1)]
search_cost(0, empty_book)
if len(ans_cost) ==0 :
  print(-1)
else:
  print(min(ans_cost))

Submission status: Accepted

Solution code:
#C
n, m, x = list(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:])
    
    
result = -1
for i in range(1 << n):
    reading_books = [0 for _ in range(m)]
    cost = 0
    for j in range(n):
        if (i >> j) & 1 == 0:
            continue
        cost += c[j]
        for k in range(m):
            reading_books[k] += a[j][k]
        if all(skill >= x for skill in reading_books):
            if result == -1:
                result = cost
            else:
                result = min(result, cost)


print(result)

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
books = []
for i in range(n):
	books.append(tuple(map(int, input().split())))

def combinations():
	from itertools import product
	
	for i in product([0, 1], repeat = n):
		lst = []
		for j in range(n):
			if i[j] == 1:
				lst.append(books[j])
		yield lst

ans = 10**9
for books_bought in combinations():
	level = [0]*m
	cost = 0
	for book in books_bought:
		cost += book[0]
		for i in range(m):
			level[i] += book[i + 1]
		
	for num in level:
		if num < x:
			break
	else:
		ans = min(ans, cost)

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

Submission status: Accepted

Solution code:
def main():
    n,m,x = map(int, input().split())
    c = [None]*n
    a = [None]*n
    
    for i in range(n):
        line = list(map(int, input().split()))
        c[i] = line[0]
        a[i] = line[1:]
    
    costs = []
    
    def func(i, points, cost, x):
        if i == n:
            if all([point >= x for point in points]):
                costs.append(cost)
            else:
                return None
        
        if all([point >= x for point in points]):
            costs.append(cost)
            return None
        
        func(i+1, points, cost, x)
        func(i+1, [points[j] +a[i][j] for j in range(m)], cost+c[i], x)
    
    func(0, [0]*m, 0, x)
    
    if len(costs) == 0:
        return -1
    
    return min(costs)

print(main())

Submission status: Accepted

Solution code:
N,M,X = [int(i) for i in input().split()]
A = []
for _ in range(N):
    A.append([int(i) for i in input().split()])
ans = float("inf")

for i in range(1,2**N):
    a = 0
    e = [0]*M
    bi = "0"*N + bin(i)[2:]
    bi = list(bi[len(bi)-N:])
    for j in range(N):
        if bi[j] == "1":
            a += A[j][0]
            for k in range(M):
                e[k] += A[j][k+1]
    c = True
    for i in range(M):
        c &= e[i] >= X
    if c:
        ans = min(ans,a)
if ans > 10**7:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
def main():
    n,m,x = map(int, input().split())
    c = [0]*n
    a = [0]*n
    
    for i in range(n):
        line = list(map(int, input().split()))
        c[i] = line[0]
        a[i] = line[1:]
    
    costs = []
    
    def func(i, points, cost, x):
        if i == n:
            if all([point >= x for point in points]):
                costs.append(cost)
            else:
                return None
        
        if all([point >= x for point in points]):
            costs.append(cost)
            return None
        
        func(i+1, points, cost, x)
        func(i+1, [points[j] +a[i][j] for j in range(m)], cost+c[i], x)
    
    func(0, [0]*m, 0, x)
    
    if len(costs) == 0:
        return -1
    
    return min(costs)

print(main())

Submission status: Accepted

Solution code:
INF = float('inf')
import copy
 
def dfs(i, C):
    if i == N:
        if min(C[1:]) >= X:
            return C[0]
        else:
            return INF
    res = INF
    res = min(res, dfs(i+1, copy.copy(C)))
    for j in range(M+1):
        C[j] = C[j] + L[i][j]
    res = min(res, dfs(i+1, copy.copy(C)))
    return res

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

ans = dfs(0, [0 for _ in range(M+1)])
if ans == INF:
    ans = -1
print(ans)

Submission status: Accepted

Solution code:
def bit_set(num:int,n:int):
  if num & (1<<n):
    return True
  return False

n,m,x = map(int,input().split())
ca_list = [list(map(int,input().split())) 
           for nesya in range(n)]
c = -1
for i in range(2**n):
  skill = [0]*m
  cost = 0
  for k in range(n):
    if bit_set(i,k) == True:
      ca =  ca_list[k]
      cost += ca[0]
      a = ca[1:]
      skill = [j+l for (j,l) in zip(skill, a)]
  if all((hoge >= x) for hoge in skill):
    if c == -1:
      c = cost
    else:
      c = min(c,cost)
print(c)