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: Runtime Error

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

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

INF = 10**9
ans = INF

for i in range(n):
  c_as = list(map(int, input().split()))
  c[i], A[i] = c_as[0], c_as[1:]
  
for s in range(0, 1 << n):
  skill = [0] * n
  money = 0
  for i in range(n):
    if(s >> i) % 2 == 0:continue
    money += c[i]
    for j in range(m):
      skill[j] += A[i][j]
  ok = True
  for j in range(m):
    if skill[j] < x:
      ok = False
  if ok:
    ans = min(ans, money)
    
if ans == INF:
  ans = -1
  
print(ans)

Submission status: Runtime Error

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

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

INF = 10**9
ans = INF

for i in range(n):
  c_as = list(map(int, input().split()))
  c[i], A[i] = c_as[0], c_as[1:]
  
for s in range(0, 1 << n):
  money = 0
  skill = [0] * n
  for i in range(n):
    if(s >> i) % 2 == 0:continue
    money += c[i]
    for j in range(m):
      skill[j] += A[i][j]
  ok = True
  for j in range(m):
    if skill[j] < x:
      ok = False
  if ok:
    ans = min(ans, money)
    
if ans == INF:
  ans = -1
  
print(ans)

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
books = [input() for i in range(N)]
result = 12 * 10**5 + 1
for i in range(1, 1 << N):
  cost = 0
  skill = [0 for i in range(N)]
  for j in range(N):
    if (i >> j) & 1:
      book = books[j].split()
      cost += int(book[0])
      for k in range(M):
        skill[k] += int(book[k + 1])
  if all(j >= X for j in skill):
    result = min(result, cost)
if result == 12 * 10**5 + 1:
  print(-1)
else:
  print(result)

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
books = [input() for i in range(N)]
result = 12 * 10**5 + 1
for i in range(1, 1 << N):
  skill = [0 for i in range(N)]
  for j in range(N):
    if (i >> j) & 1:
      book = books[j].split()
      cost += int(book[0])
      for k in range(M):
        skill[k] += int(book[k + 1])
  if all(j >= X for j in skill):
    result = min(result, cost)
if result == 12 * 10**5 + 1:
  print(-1)
else:
  print(result)

Submission status: Runtime Error

Solution code:
N,M,X = map(int,input().split())
CA = [[0] * N for i in range(M)]
CS = [0]*N

for i in range(N):
  CA[i]=list(map(int,input().split()))
  CS[i]=CA[i][0]

print(CA)

Submission status: Runtime Error

Solution code:
n, m, x = map(int, input().split())
A = [[] for _ in range(n)]
cost = [0] * n
for i in range(n):
  c_as = list(map(int, input().split()))
  cost[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: Runtime Error

Solution code:
from itertools import combinations
import numpy as np
n,m,x = map(int,input().split())
a_list = []
price_list = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    price_list.append(tmp.pop(0))
    a_list.append(tmp)
    
all_list = [x for x in range(len(a_list))]
prices = []
for i in range(1,len(a_list)+1):
    for y in combinations(all_list,i):
        tmp = np.zeros(3)
        price = 0
        for ch in y:
            tmp += np.array(a_list[ch])
            price += price_list[ch]
        if np.all(tmp>=x):
            prices.append(price)
if prices != []:
    print(min(prices))
else:
    print(-1)

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split(' '))
cost = []
A = []
a = 0 
for _ in range(N):
    l = list(map(int, input().split(' ')))
    cost.append(l[0])
    A.append(l[1:])

ans = 10**10

for i in range(1,2 ** N):
    a = 0
    price = 0
    compare = [0]*M
    for j in range(N):
        if ((i >> j) & 1) == 1:
            price += cost[j]
            for k in range(M):
                compare[j] += A[k][j]
            for m in range(M):
                if compare[m] >= X:
                    a+=1
            if a == M:
                ans = min(ans,price)
if ans == 10 ** 10:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import copy
n,m,a = map(int,input().split())
b = list()
for i in range(n):
    b.append(list(map(int,input().split())))

def search(num,x,sum):
    if num == n:
        flag = True
        for i in range(m):
            if x[i] < a:
                flag = False
        if flag:
            return sum
        else:
            return 10**6
    y = copy.copy(x)
    sum1 = sum + b[num][0]
    for i in range(m):
        y[i] += b[num][i+1]
    return min(search(num+1,x,sum),search(num+1,y,sum1))
c = search(0,[0 for i in range(n)],0)
if c == 10**6:
    print(-1)
else:
    print(c)

Submission status: Runtime Error

Solution code:
import copy
n,m,a = map(int,input().split())
b = list()
for i in range(n):
    b.append(list(map(int,input().split())))
print(n,m,a,b)

def search(num,x,sum):
    if num == n:
        flag = True
        for i in range(m):
            if x[i] < a:
                flag = False
        if flag:
            return sum
        else:
            return 10**6
    y = copy.copy(x)
    sum1 = sum + b[num][0]
    for i in range(m):
        y[i] += b[num][i+1]
    return min(search(num+1,x,sum),search(num+1,y,sum1))
c = search(0,[0 for i in range(n)],0)
if c == 10**6:
    print(-1)
else:
    print(c)

Submission status: Runtime Error

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

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: Runtime Error

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

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: Runtime Error

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])
            flag =True
if flag ==True:
    print(out)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
def task(n, m, x, c, a):
    mx = [0] * n
    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 = 1000000
    for i in range(1, (2**n) + 1):
        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: Runtime Error

Solution code:
def rec(c, a, x, n, m, start, states, best, price):

    for i in range(start, n):
        price += c[i]

        found = True
        for j in range(0, m):
            states[j] += a[i][j]

            if states[j] < x:
                found = False

        if found and price < best:
            best = price

        if i < n - 1:
            best = rec(c, a, x, n, m, i + 1, states, best, price)

        for j in range(0, m):
            states[j] -= a[i][j]

        price -= c[i]

    return best


def task(n, m, x, c, a):
    mx = [0] * n
    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 = 0
    # for i in range(1, 2 ^ n + 1):
    #     price = 0
    #     states = [0] * m
    #     for j in range(0, n):
    #         if ((i >> j) & 1):
    #             price += c[j]
    #             for k in range(0, m):
    #                 states[m] += a[k]
    #                 states[m] += a[k]
    #                 states[m] += a[k]

    best = rec(c, a, x, n, m, 0, states, 1000000, 0)

    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: Runtime Error

Solution code:
def rec(c, a, x, n, m, start, states, best, price):

    for i in range(start, n):
        price += c[i]
        states[0] += a[i][0]
        states[1] += a[i][1]
        states[2] += a[i][2]

        if states[0] >= x and states[1] >= x and states[2] >= x and price < best:
            best = price

        if i != n - 1:
            best = rec(c, a, x, n, m, i + 1, states, best, price)

        states[0] -= a[i][0]
        states[1] -= a[i][1]
        states[2] -= a[i][2]
        price -= c[i]

    return best


def task(n, m, x, c, a):
    mx = [0] * n
    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

    best = rec(c, a, x, n, m, 0, [0, 0, 0], 1000000, 0)

    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: Runtime Error

Solution code:
def rec(c, a, x, n, m, start, states, best, price):

    for i in range(start, n):
        price += c[i]
        states[0] += a[i][0]
        states[1] += a[i][1]
        states[2] += a[i][2]

        if states[0] >= x and states[1] >= x and states[2] >= x and price < best:
            best = price

        if i != n - 1:
            best = rec(c, a, x, n, m, i + 1, states, best, price)

        states[0] -= a[i][0]
        states[1] -= a[i][1]
        states[2] -= a[i][2]
        price -= c[i]

    return best


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

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

    best = rec(c, a, x, n, m, 0, [0, 0, 0], 1000000, 0)

    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: Runtime Error

Solution code:
import sys
import itertools
n, m, x=map(int, input().split())
text = [list(map(int, i.strip('\n').split())) for i in sys.stdin]
num_tex = [i for i in range(1, len(text) + 1)]
all_c = []
for comb in num_tex:
    for v in itertools.combinations(text, comb):
        sum_a = []
        for j in range(1, len(v[0])):
            sum_a.append(sum([v_[j] for v_ in v]))
        if all([x <= sum_a_ for sum_a_ in sum_a]):
            all_c.append(sum([v_[0] for v_ in v]))
print(sorted(all_c)[0])

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
List = [list(map(int, input().split())) for n in range(N)]
INF = 10**7
ans = INF
C_pro = list(itertools.product([0,1], repeat=N))

for c_pro in C_pro:
    count = 0
    cost = 0
    ans_list = [0 for i in range(M)]
    for c in c_pro:
        if c == 1:
            cost += List[count][0]
            ans_list = [ans+list for ans, list in zip(ans_list,List[count][1:])]
        count += 1
    if ans_list >= [X for i in range(M)]:
        ans = min(ans, cost)
    

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

Submission status: Runtime Error

Solution code:
n, m, x = map(int, input().split())
l = []
dp = [[] for _ in range(n)]
for _ in range(n):
  a = list(map(int, input().split()))
  l.append(a)
dp[0].append([0] * (m+1))
ans = []
for i in range(n):
  for row in dp[i]:
    dp[i+1].append(row)
    cnt = 0
    for j in range(m+1):
      if j == 0:
        row[0] += l[i][0]
      else:
        row[j] += l[i][j]
        if row[j] >= x:
          cnt += 1
    if cnt == m:
      ans.append(row[0])
    dp[i+1].append(row)
if len(ans) == 0:
  print(-1)
else:
  ans.sort()
  print(ans[0])

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, X = list(map(int, input().split()))
a = [list(map(int, input().split())) for l in range(N)]
a = np.array(a)
tmp = np.zeros(M+1)
ans = []
for k in range(1,N):
  for i in range(N):
    for j in range(i+1,N):
      tmp = a[i:i+1][0:M] + np.sum(a[j:j+k][0:M], axis = 0)
      if np.min(tmp[0][1:M]) >= X:
        ans.append(tmp[0][0])
ans = np.array(ans)      
if len(ans)>0:
  print(np.min(ans))
else:
  print(-1)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    n, m, x = list(map(int, input().split()))

    c = []
    a = []

    for i in range(n):
        c_temp, *a_temp = list(map(int, input().split()))  
        c.append(c_temp)
        a.append(a_temp)

    INF = float("inf")
    ans = INF

    for bit in range(1 << n):
        price = calc_price(bit) 
        ans = min(ans, price) 

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

def calc_price(bit):
    price_total = 0 
    learn_total = [0] * m 

    for i in range(n):
        if (bit >> i) & 1:  
            price_total += c[i]  
            learn = a[i]  
            for j, la in enumerate(learn): 
                learn_total[j] += la

   
    if check(learn_total):
        return price_total 
    else:
        return INF 

def check(learn_total):
    for i in range(m):
        if learn_total[i] < x:
            return False  
    return True

Submission status: Runtime Error

Solution code:
#coding utf-8
if __name__ == '__main__':
    n, m, x = list(map(int, input().split()))

    # 空のリストを作って、appendで追加していきます
    c = []  # 参考書の値段です
    a = []  # 各参考書に入る理解度です

    for i in range(n):
        c_temp, *a_temp = list(map(int, input().split()))  # こうすると、2つ目以降をリストで受け取れます
        c.append(c_temp)
        a.append(a_temp)

    INF = float("inf")
    ans = INF

    for bit in range(1 << n):
        price = calc_price(bit)  # 条件を満たすならそのときの値段、満たさないならINFが返ってきます
        ans = min(ans, price)  # 答えを更新します

    if ans == INF:
        print(-1)  # どうやっても条件を満たせなかった
    else:
        print(ans)

def calc_price(bit):
    price_total = 0  # 値段の合計
    learn_total = [0] * m  # 理解度

    for i in range(n):
        if (bit >> i) & 1:  # i桁目が0か1か見て、i冊目を買うか買わないか判定します
            price_total += c[i]  # 買うので、i冊目の値段を加算します
            learn = a[i]  # 「i冊目の参考書を読んで増える、各アルゴリズムの理解度」のリストです
            for j, la in enumerate(learn):  # 理解度を加算します enumerateを使うと、range(n)よりスマートです
                learn_total[j] += la

    # 条件を満たすか、check関数で確認します
    if check(learn_total):
        return price_total #条件を満たすので、値段を返します
    else:
        return INF # 条件を満たさないので、INFを返します

def check(learn_total):
    for i in range(m):
        if learn_total[i] < x:
            return False  # 1個でもx未満ならFalse
    return True # 全部x以上ならTrue

Submission status: Runtime Error

Solution code:
from itertools import  product
N,M,X = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(N)]
for i in range(1,M+1):
    count=0
    for j in range(N):
        count+=ca[j][i]
    if count<X:
        print(-1)
        exit()

ans = 10**9
for z in product((0, 1), repeat=N):#bit全探索のくみあわせを勝手に作ってくれるので使うとよい
    count=0
    count2=[0]*M
    for i in range(N):
        if z[i]==1:
            count+=ca[i][0]
            for j in range(1,M+1):
                count2[j-1]+=ca[i][j]
    
    for i in range(m):
        if count2[i]<x:
            break
    else:
        ans=min(count,ans)
print(ans)

Submission status: Runtime Error

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

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

C.sort()
n = len(C)
items = []
for i in range(2 ** n):
    item = []
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            item.append(C[j])  # フラグが立っていたら bag に果物を詰める
    items.append(item)

for i in range(1,len(items)):
    sum = 0
    a1 = 0
    a2 = 0
    a3 = 0
    for j in range(len(items[i])):
        index = items[i][j][1]
        a1 += A[index][0]
        a2 += A[index][1]
        a3 += A[index][2]
        sum += items[i][j][0]
    if a1 >= X and a2 >= X and a3 >= X:
        success.append(sum)
if len(success) == 0:
    print(-1)
else:
    print(min(success))

Submission status: Runtime Error

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

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

C.sort()
n = len(C)
items = []
for i in range(2 ** n):
    item = []
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            item.append(C[j])  # フラグが立っていたら bag に果物を詰める
    items.append(item)

print(items)
for i in range(1,len(items)):
    sum = 0
    a1 = 0
    a2 = 0
    a3 = 0
    for j in range(len(items[i])):
        index = items[i][j][1]
        a1 += A[index][0]
        a2 += A[index][1]
        a3 += A[index][2]
        sum += items[i][j][0]
    if a1 >= X and a2 >= X and a3 >= X:
        success.append(sum)
if len(success) == 0:
    print(-1)
else:
    print(min(success))

Submission status: Runtime Error

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

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

C.sort()
n = len(C)
items = []
for i in range(2 ** n):
    item = []
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            item.append(C[j])  # フラグが立っていたら bag に果物を詰める
    items.append(item)


for i in range(1,len(items)):
    sum = 0
    a1 = 0
    a2 = 0
    a3 = 0
    for j in range(len(items[i])):
        a1 += A[items[i][j][1]][0]
        a2 += A[items[i][j][1]][1]
        a3 += A[items[i][j][1]][2]
        sum += items[i][j][0]
    if a1 >= X and a2 >= X and a3 >= X:
        success.append(sum)
if len(success) == 0:
    print(-1)
else:
    print(min(success))

Submission status: Runtime Error

Solution code:
n,m,x=map(int,input().split())
a=[list(map(int,input().split()))]
ans=[]
for bit in range(1<<n):
  total=0
  skill=[0]*m
  for i in range(n):
    if bit & (1<<i):
      total+=a[i][0]
      for j in range(m):
        skill[j]+=a[i][j]
  if all([k>x for k in skill]):
    ans.append(total)
print(min(total) if len(ans)>=1 else -1)

Submission status: Runtime Error

Solution code:
n,m,x=map(int,input().split())
a=[list(map(int,input().split()))]
ans=[]
for bit in range(1<<n):
  total=0
  skill=[0]*m
  for i in range(n):
    if bit & (1<<i):
      total+=a[i][0]
      for j in range(m):
        skill[j]+=a[i][j]
  if all([k>K for k in skill]):
    ans.append(total)
print(min(total) if len(ans)>=1 else -1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def solve(i, cost, know, x, a):
    global res
    if i == len(a):
        for j in range(m):
            if know[j] < x:
                return
        res = min(res, cost)
        return
    solve(i + 1, cost, know, x, a)
    for j in range(m):
        know[j] += a[i][j + 1]
    solve(i + 1, cost + a[i][0], know, x, a)
    for j in range(m):
        know[j] -= a[i][j + 1]
fin = open('input.txt', 'r')
n, m, x = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
know = [0] * (m)
res = 10 ** 7
solve(0, 0, know, x, a)
print(res if res != 10 ** 7 else - 1)

Submission status: Runtime Error

Solution code:
nmx=list(map(int, input().split()))
N=nmx[0]
M=nmx[1]
X=nmx[2]
mylist=[]
for i in range(N):
    mylist.append(list(map(int, input().split())))
Ans=10000*12+1
for i in range(2**N):
    A=[[0]*M]
    C=0
    for j in range(N):
        if (i>>j) & 1:
            C+=mylist[j][0]
            for k in range(M):
                A[k]=A[k]+mylist[j][k+1]
    if min(A)>=X:
        #Ans=min(Ans, C)
if Ans==10000*12+1:
    print(-1)
else:
    print(Ans)

Submission status: Runtime Error

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

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

#print(a,c)

ans = 10 ** 8

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

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from itertools import product

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

#print(c)
#print(a)

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

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

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

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

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

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from itertools import product

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

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

for p in range(2**n):
    state = [0] * n
    for j in range(n):
        state[j] = (p >> j) & 1

    a_val = [0] * n
    c_yen = 0

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

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

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

Submission status: Runtime Error

Solution code:
import itertools

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

p = []
p.extend([0]*N)
p.extend([1]*N)
mm = list(set(itertools.permutations(p , N)))

sum_list = [0]*N
c_list = [0]*len(mm)
ans = 10**18
for i in range(len(mm)):
    for j in range(len(mm[i])):
        if mm[i][j] == 1:
            c_list[i] += A[j][0]
            for k in range(M):
                sum_list[k] += A[j][k+1]
    if all([True if i >= X else False for i in sum_list]):
        ans = min(ans , c_list[i])
    sum_list = [0]*N
if ans == 10**18:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product

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

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

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

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

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

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