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:


import numpy as np
N,M,X = map(int,input().split())
arr = np.array([list(map(int,input().split())) for i in range(n)])
C = arr.T[0]
A = arr.T[1:].T


cost = np.zeros(1<<N, np.int64)
ability = np.zeros((1<<N, M), np.int64)
for i in range(N):
    cost[1<<i:1<<(i+1)] = cost[:1<<i] + C[i]
    ability[1<<i:1<<(i+1)] = ability[:1<<i] + A[i]

ok = np.all(ability >= X, axis=1)

x = cost[ok]
answer = -1 if len(x) == 0 else x.min()
print(answer)

Submission status: Runtime Error

Solution code:
from itertools import product
from itertools import combinations
import numpy as np

def resolve():
  N, M, X = map(int, input().split(" "))

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books).reshape([N, M + 1])

  books_index_pattarns = [list(x) for i in range(1, N) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)]
  # books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)][:,:1]

  if len(books_result) == 0:
    print(-1)
    return True
  elif len(books_result) == 1:
    print(books_result[0])
    return True
  else:
    print(books_result[:,:1].min())
    return True

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import combinations_with_replacement

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

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M+1):
  if sums[i] < X:
    OK = False
    break

if OK == False:
  print(-1)
else:
  As = []
  for A in combinations_with_replacement(range(0, N), r=M):
    As.append(tuple(set(A)))
  As = list(map(list, set(As)))
  last_val = sums[0]
  for ls in As:
    ls = list(set(ls))
    ans = [0] * M
    val = 0
    for a in ls:
      for ix,i in enumerate(CA[a-1][1:]):
        ans[ix] += i
      val += l[a-1][0]
    b = [i for i in ans if i >= X]
    if len(b) == len(ans):
      last_val = min(last_val, val)
  print(last_val)

Submission status: Runtime Error

Solution code:
s,t = input().split()
a,b = map(int,input().split())
u = input()

if u == s:
  print((a-1),b)
else:
  print(a,(b-1))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
from itertools import product
from itertools import combinations
import numpy as np

def resolve():
  N, M, X = map(int, input().split(" "))

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books)

  books_index_pattarns = [list(x) for i in range(1, N) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)][:,:1]
  if len(books_result) == 0:
    print("-1")
    return True
  else:
    print(books_result.min())
    return True

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
def resolve():
  N, M, X = map(int, input().split(" "))

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books)

  books_index_pattarns = [list(x) for i in range(1, N) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  # books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)]
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)][:,:1]
  if len(books_result) == 0:
    print("-1")
    return True
  else:
    print(books_result.min())
    return True

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
N,M,X=map(int,input().split())
l=[]
for i in range (N):
  l.append(list(map(int,input().split())))
ans=10000000
for i in range(2**N):
  score=[0]*M
  coin=0
  for j in range(N):
    if i>=2**(N-1-j):
      for p in range(M):
        score[p]+=l[j][p+1]
      coin+=l[j][0]
      i-=2**(N-1-j)
  flag=0
  for q in range(M):
    if score[q]<X:
      flag=1
  if flag==0:
    if ans>coin:
      ans=coin
if ans=10000000:
  print("-1")
else:
  print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np

def resolve():
  N, M, X = map(int, input().split(" "))

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books)

  books_index_pattarns = [list(x) for i in range(1, N) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)][:,:1]
  if len(books_result) == 0:
    print("-1")
    return True
  else:
    print(books_result.min())

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
n,m,x = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ans = float('inf')

for i in range(2**n):
    sum = [0]*(M+1)
    # n桁について調査
    for j in range(n):
        # iのj桁目が1かどうかcheck
        if ((i >> j) & 1):
            for k in range(M+1):
                sum[k] += l[j][k]
    if sum[0] < ans:
        for a in range(1,m+1):
            if sum[a] < x:
                break
            else:
                ans = sum[0]
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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

cost = []

skill = list(zip(*CA))

for i in range(1, M+1):
    if sum(skill[i]) < X:
        print(-1)
        exit()

for i in range(1, N):
    for balls in list(itertools.combinations(CA, i)):
        test = np.zeros(M+1)
        for j in balls:
            jtest = np.asarray(j)
            test = test + jtest

        if min(test[1:])>=X:
            cost.append(test[0])

print(int(min(cost)))

Submission status: Runtime Error

Solution code:
N,M,X=map(int,input().split())
l=[]
for i in range (N):
  l.append(list(map(int,input().split())))
ans=0
for i in range(2**N):
  score=[0]*M
  coin=0
  for j in range(N):
    if i>=2**(N-1-j):
      for p in range(M):
        score[p]+=l[j][p+1]
        coin+=l[j][0]
      i-=2**(N-1-j)
  flag=0
  for q in range(M):
    if score(q)<X:
      flag=1
  if flag==0:
    if ans<coin:
      ans=coin
print(coin)

Submission status: Runtime Error

Solution code:
N,M,X=list(map(int,input().split()))
AC=[]
C=[]
A=[]
for n in range(N):
  AC.append(list(map(int,input().split())))
  C.append(AC[0])
  A.append(AC[1:])
ans=0
for n in range(2**N):
  total=0
  und=[0]*M
  for j in range(N):
    if n >> j & 1:
      total+=C[j]
      for m in range(M):
        und[m]+=A[j][m]
  if X <= min(und):
    ans=total
if ans==0:
  print(-1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
import itertools
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)

out = 10**18
for c in itertools.product([False, True], repeat=M):
    tmp = np.sum(items[np.where(c)], axis=0)
    if np.any(tmp):
      if M == np.count_nonzero(tmp[1:] >= X):
        out = min(out, tmp[0])
if out == 10**18:
  print(-1)
else:
  print(out)

Submission status: Runtime Error

Solution code:
import itertools
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)

out = 10**18
for c in itertools.product([False, True], repeat=M):
    tmp = np.sum(items[[np.where(c)]], axis=0)
    if np.any(tmp):
      if M == np.count_nonzero(tmp[1:] >= X):
        out = min(out, tmp[0])
if out == 10**18:
  print(-1)
else:
  print(out)

Submission status: Runtime Error

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

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])#参考書を使わない場合

                for j in range(1,m+1):#参考書を使う場合
                    i_sum[j-1] += sp[i-1][j]
                cost[0] += sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

Submission status: Runtime Error

Solution code:

if __name__ == '__main__':
    n, m, x = tuple(map(int, input().split()))
    l = []
    total = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    for i in range(0, n):
        temp = list(map(int, input().split()))
        l.append(temp)
        for j in range(0, len(temp)):
            total[j] = temp[j] + total[j]
    total = total[:m+1]
    minimum = [total[0]]


    def is_valid(l4):
        return len(l4)-1 == len(list(filter(lambda a: a >= x, l4[1:])))


    def search(l1, l2):
        if l1 == []:

            if is_valid(l2) and minimum[0] > l2[0]:

                minimum[0] = l2[0]
            return
        l3 = l2[0:]
        for i in range(0, len(l2)):
            l3[i] = l1[-1][i] + l2[i]
        search(l1[:-1], l3)
        search(l1[:-1], l2)
        return

    if not is_valid(total):
        print(-1)
    else:
        search(l, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0:m+1])
        print(minimum[0])

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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

cost = []

skill = list(zip(*CA))

for i in range(1, M+1):
    if sum(skill[i]) < X:
        print(-1)
        exit()

for i in range(N):
    for balls in list(itertools.combinations(CA, i)):
        test = np.zeros(M+1)
        for j in balls:
            jtest = np.array(j)
            test = test + jtest

        if min(test[1:])>=X:
            cost.append(test[0])

print(int(min(cost)))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, X = map(int,input().split())
l = []
li = np.array([])
for i in range(N):
  l.append(list(map(int,input().split())))

li = np.array(l)

skill_sum = []
for j in range(2**N):
  sum = np.zeros([M+1])
  for k in range(N):
    if ((j >> k) & 1):
        sum += li[k] 
  skill_sum.append(list(sum))      
pricelist = []
for l in range(2**N):
  cnt = 0
  for m in range(M):
    if skill_sum[l][m+1] >= X:
      cnt += 1
  if cnt ==  M:
    pricelist.append(int(skill_sum[l][0]))
    
print(min(pricelist))

Submission status: Runtime Error

Solution code:
n, m, x = map(int,input().split())
c = [list(map(int, input().split())) for i in range(n)]
ans = float('inf')
money = []

for i in range(2**n):
  temp_money = 0
  temp_skill = [0]*m
  for j in range(n):
    if (i >> j) & 1:
      temp_money += c[j][0]
      temp_skill = [a + b for a, b in zip(temp_skill, c[j][1:m+1])]
    if all([i >= x for i in temp_skill])==True:
      money.append(temp_money)

ans = min(ans,min(money))
if ans == float("inf"):
  ans = -1

print(ans)

Submission status: Runtime Error

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

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])#参考書を使わない場合

                for j in range(1,m+1):#参考書を使う場合
                    i_sum[j-1] += sp[i-1][j]
                cost[0] += sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

Submission status: Runtime Error

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

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        print(i,i_sum,cost)
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])#参考書を使わない場合

                for j in range(1,m+1):#参考書を使う場合
                    i_sum[j-1] += sp[i-1][j]
                cost[0] += sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost[:])
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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

cost = []

nums=[]
for i in range(1, M+1):
    nums.append(i)

skill = list(zip(*CA))

for i in range(1, M+1):
    if sum(skill[i]) < X:
        print(-1)
        exit()

for i in range(N):
    for balls in list(itertools.combinations(CA, i)):
        test = np.zeros(M+1)
        for j in balls:
            jtest = np.asarray(j)
            test = test + jtest

        if min(test[1:])>=X:
            cost.append(test[0])

print(int(min(cost)))

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
n, m, x = list(map(int, input().split()))
cl = [0] * n
al = [[]*m for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    cl[i] = tmp[0]
    al[i] = tmp[1:]


def dfs(status, book):
    for i in range(m):
        status[i] += book[i]
    return status


ans = 10**10
for bit in product([0, 1], repeat=n):
    # print(bit)
    status = [0]*n
    money = 0
    for i, b in enumerate(list(bit)):
        if b == 1:
            status = dfs(status, al[i])
            money += cl[i]
    flag = True
    for i in range(n):
        if status[i] >= x:
            continue
        else:
            flag = False
    if flag:
        ans = min(ans, money)
if ans == 10**10:
    print(-1)
    exit()
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
n, m, x = list(map(int, input().split()))
cl = [0] * n
al = [[]*m for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    cl[i] = tmp[0]
    al[i] = tmp[1:]


def dfs(status, book):
    for i in range(m):
        status[i] += book[i]
    return status


ans = 10**10
for bit in product([0, 1], repeat=n):
    # print(bit)
    status = [0]*m
    money = 0
    for i, b in enumerate(list(bit)):
        if b == 1:
            status = dfs(status, al[i]):
            money += cl[i]
    flag = True
    for i in range(m):
        if status[i] >= x:
            continue
        else:
            flag = False
    if flag:
        ans = min(ans, money)
if ans == 10**10:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

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

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost)#参考書を使わない場合

                for j in range(1,m+1):#参考書を使う場合
                    i_sum[j-1] += sp[i-1][j]
                cost[0] +=  sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost)
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

Submission status: Runtime Error

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

import copy
result = []
def test(i,i_sum,cost):
    
    flag = 0
    if i <= n:
        print(i,i_sum,cost)
        for j in range(m):
            if i_sum[j] < x:
                flag = 1
                break

        if flag == 1:
                test(copy.deepcopy(i)+1, i_sum[:],cost)#参考書を使わない場合

                for j in range(1,m+1):#参考書を使う場合
                    i_sum[j-1] += sp[i-1][j]
                cost[0] +=  sp[i-1][0]
                test(copy.deepcopy(i)+1, i_sum[:],cost)
        else:
            result.append(cost[0])
test(0,[0]*n,[0])

if result != []:
    print(min(result))
else:
    print(-1)

Submission status: Runtime Error

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

def generate_n_bit(n):
    bins= []
    for i in range(2**n):
        bins.append(list(str(format(i,'b').zfill(n))))
    
    return bins

min_price = 10**9
bins = generate_n_bit(10)
bins = bins[1:]

for bin in bins:
    a = [0 for k in range(m)]
    price = 0
    for i in range(n):
        if bin[i] == '1':
            for j in range(m):
                a[j] += l[i][j+1]
            
            price += l[i][0]
    
   
    
    if min(a) >= x:
        min_price = min(price, min_price)
        

if min_price == 10**9:
    print(-1)
    exit()
    
print(min_price)

Submission status: Runtime Error

Solution code:
n, m, x = [int(x) for x in input().split()]
c = []
a = []
for i in range(n):
  tmp = [int(x) for x in input().split()]
  c.append(tmp[0])
  a.append(tmp[1:])
#全探索
ans = 10**8 # as INF
for s in range(2**n):
  s = bin(s)
  cost = 0
  d = [0 for j in range(m)]
  for i in range(n):
    is_use = bin(s>>i&1) == bin(1)
    if is_use:
      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 and cost < ans:
    ans = cost
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

def combinations(iterable, r):
    # combinations('ABCD', 2) --> AB AC AD BC BD CD
    # combinations(range(4), 3) --> 012 013 023 123
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    yield tuple(pool[i] for i in indices)
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        yield tuple(pool[i] for i in indices)

def main():

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

    l= []

    for i in range(n):
        for pair in combinations(matrix, i+1):
            row_sum = np.sum(pair, axis=0)
            for j in range(len(row_sum)):
                if j == 0:
                    continue
                if row_sum[j] < x:
                    break
                l.append(row_sum[0])
    if len(l) == 0:
        print('-1')
    else:
        print(min(l))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
ef can_reach_the_goal(u, x):
    return min(u) >= x

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

c = []
a = []
for i in range(n):
    ca = [int(row) for row in input().split()]
    c.append(ca[0])
    a.append(ca[1:])

INF = 10**7
min_cost = INF
for k in range(2**n):
    purchase = [True if c == '1' else False for c in list(format(k, '0{}b'.format(n)))]
    cost = 0
    u = [0]*m
    for i in range(n):
        cost += c[i] if purchase[i] else 0
        for j in range(m):
            u[j] += a[i][j] if purchase[i] else 0

    if can_reach_the_goal(u, x) and cost < min_cost:
        min_cost = cost

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

def combinations(iterable, r):
    # combinations('ABCD', 2) --> AB AC AD BC BD CD
    # combinations(range(4), 3) --> 012 013 023 123
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    yield tuple(pool[i] for i in indices)
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        yield tuple(pool[i] for i in indices)

def main():

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

    l= []

    for i in range(N):
        for pair in combinations(matrix, i+1):
            row_sum = np.sum(pair, axis=0)
            for j in range(len(row_sum)):
                if j == 0:
                    continue
                if row_sum[j] < X:
                    break
                l.append(row_sum[0])
    if len(l) == 0:
        print('-1')
    else:
        print(min(l))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#c
n,m,x=map(int, input().split())
sp = [list(map(int, input().split())) for _ in range(m)]
import copy
result = []
def test(i,i_sum,cost):
    flag = 0
    
    for j in range(m):
        if i_sum[j] < x:
            flag = 1
            break
    
    if flag == 1:
        
        if i <= n:
            test(copy.deepcopy(i)+1, i_sum,cost)#参考書を使わない場合
            
            for j in range(1,m+1):#参考書を使う場合
                i_sum[j-1] += sp[i-1][j]
            cost[0] +=  sp[i-1][0]
            test(copy.deepcopy(i)+1, i_sum,cost)
    else:
        result.append(cost[0])
test(0,[0]*n,[0])
print(min(result))

Submission status: Runtime Error

Solution code:
from itertools import combinations as co
n,m,x=map(int,input().split())
A=[[] for i in range(m)]
ansl=[]
for i in range(n):
    A[i].append(map(int,input().split()))
for i in range(n):
    for j in range(1,m+1):
        if A[i][j]<x:
            break
        if j==m:
            ansl.append(A[i][0])

if n==1:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for i,j in co(range(n),2):
    for k in range(1,m+1):
        if A[i][k]+A[j][k]<x:
            break
        if k==m:
            ansl.append(A[i][0]+A[j][0])
if n==2:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for i,j,k in co(range(n),3):
    for l in range(1,m+1):
        if A[i][l]+A[j][l]+A[k][l]<x:
            break
        if l==m:
            ansl.append(A[i][0]+A[j][0]+A[k][0])
if n==3:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for h,i,j,k in co(range(n),4):
    for l in range(1,m+1):
        if A[h][l]+A[i][l]+A[j][l]+A[k][l]<x:
            break
        if l==m:
            ansl.append(A[h][0]+A[i][0]+A[j][0]+A[k][0])
if n==4:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for g,h,i,j,k in co(range(n),5):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [g,h,i,j,k]]))
if n==5:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for f,g,h,i,j,k in co(range(n),6):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [f,g,h,i,j,k]]))
if n==6:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for e,f,g,h,i,j,k in co(range(n),7):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [e,f,g,h,i,j,k]]))
if n==7:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for d,e,f,g,h,i,j,k in co(range(n),8):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [d,e,f,g,h,i,j,k]]))
if n==8:
    print(min(ansl))
    quit()
for c,d,e,f,g,h,i,j,k in co(range(n),9):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [c,d,e,f,g,h,i,j,k]]))
if n==9:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for b,c,d,e,f,g,h,i,j,k in co(range(n),10):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [b,c,d,e,f,g,h,i,j,k]]))
if n==10:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for a,b,c,d,e,f,g,h,i,j,k in co(range(n),11):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [a,b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [a,b,c,d,e,f,g,h,i,j,k]]))
if n==11:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for a0,a,b,c,d,e,f,g,h,i,j,k in co(range(n),12):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [a0,a,b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [a0,a,b,c,d,e,f,g,h,i,j,k]]))
if n==12:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()

Submission status: Runtime Error

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

def generate_n_bit(n):
    bins= []
    for i in range(2**n):
        bins.append(list(str(format(i,'b').zfill(n))))
    
    return bins

min_price = 10**9
bins = generate_n_bit(10)
del bins[0]

for bin in bins:
    a = [0 for k in range(m)]
    price = 0
    for i in range(n):
        if bin[i] == '1':
            for j in range(m):
                a[j] += l[i][j+1]
            
            price += l[i][0]
    
   
    
    if min(a) >= x:
        min_price = min(price, min_price)
        print(min_price)


print(min_price)

Submission status: Runtime Error

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

CAM = list([list(map(int,input().split())) for i in range(N)])
# print(CAM)
minn = 10**18
b = False

for i in range(2 ** N):
  s = 0
  x = 0
  y =0
  z=0
  for j in range(N):  # このループが一番のポイント
      if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
        s += CAM[j][0]
        x += CAM[j][1]
        y += CAM[j][2]
        z += CAM[j][3]

  if x >= X and y >= X and z >= X:
    minn = min(s,minn)
    b = True

print(minn if b == True else -1)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

def df(arg, score, tmp,args):
    tmps = []
    if arg==N:
        if len(np.where(score>=X)[0]) == M:
            return tmp
        else:
            return 0
    check = df(arg+1, score, tmp, args)
    if check:
        if type(check)==list:
            tmps.extend(check)
        else:
            tmps.append(check)
    check = df(arg+1, score+scores[arg], tmp+values[arg], args+[arg])
    if check:
        if type(check)==list:
            tmps.extend(check)
        else:
            tmps.append(check)
    if tmps == []:
        return 0
    else:
        return tmps

tmp = df(0, np.zeros(M), 0, [])
if tmp != []:
    print(min(tmp))
else:
    print(-1)

Submission status: Runtime Error

Solution code:
n,m,x = map(int,input().split())
li1 = []
li2 = []
for i in range(n):
    li1.append(list(map(int,input().split())))
for i in range(2**n):
    b = '0'*(n-len(bin(i))+2)+bin(i)[2:]
    total = 0
    li3 = [0]*m
    f = 1
    for j in range(n):
        if b[j] == "1":
            total += li1[j][0]
            for k in range(m):
                li3[k] += li1[j][k+1]
    for j in range(m):
        if li3[j] < x:
            f = 0
    if f == 1:
        li2.append(total)
print(min(li2))

Submission status: Runtime Error

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m,x=n1()
ca=n3(n)
ca
ans=9999999999

import itertools
book=list(itertools.product([0,1], repeat=n))
price=[]
for line in book:
    p=0
    for i in range(n):
        if line[i]==1:
            p+=ca[i][0]
            
    price.append(p)
for i in range(len(book)):
    t=book[i]
    s=[0]*m
    for j in t:
        if t[j]==1:
            s=[s[k]+ca[j][k+1] for k in range(m)]
    if len([y for y in s if y>=x])==m:
        ans=min(ans,price[i])
if ans==9999999999:
    print(-1)
else:
    print(ans)