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:
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 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 == INIT:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
def main():
    n, m, x = map(int, input().split())
    books = []
    for _ in range(n):
        books.append(tuple(map(int, input().split())))

    books_set_all = []
    books_pattern = product((0, 1), repeat=n)
    for each_pattern in books_pattern:
        books_set = [0] * (m + 1)
        for i in each_pattern:
            if i:
                for i2 in range(m + 1):
                    books_set[i2] += books[i][i2]
        books_set_all.append(books_set)
    price_all = []
    for ebs in books_set_all:
        price = ebs[0]
        ebs[0] = x
        if len([j for j in ebs if j >= x]) == m + 1:
            price_all.append(price)
    if len(price_all) > 0:
        print(min(price_all))
    else:
        print(-1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**9
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(0,2**N):
    cost = 0
    know = [0]*M
    for j in range(N):
        if i >> j & 1==1:
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]

    for j in know:
        if j < X:
            break
    else:
        ans = min(ans, cost)
if ans==10**9:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**9
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(0,2**N):
    cost = 0
    know = [0]*M
    for j in range(N):
        if (i >> j) & 1==1:
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]

    for j in know:
        if j < X:
            break
    else:
        ans = min(ans, cost)
if ans==10**9:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**9
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(0,2**N):
    cost = 0
    know = [0]*M
    for j in range(N):
        if (i >> j) & 1==1:
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
    for j in know:
        if j < X:
            break
    else:
        ans = min(ans, cost)
if ans==10**9:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**9
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(0,2**N):
    cost = 0
    know = [0]*M
    for j in range(N):
        if (i >> j) & 1==1:
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
    for j in know:
        if j < X:
            break
    else:
        ans = min(ans, cost)
if ans==10**9:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**9
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(0,2**N):
    cost = 0
    know = [0]*M
    for j in range(N):
        if (i >> j) & 1==1:
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
if ans==10**9:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

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

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

F=[0]*2**N
T=1
S=[12*10**6]
for i in range(2**N):
    skill=[0]*M
    T=1
    kingaku=0
    j=i
    binj=bin(j)
    for k in range(len(binj)-2):
        if ((i >> k) & 1):
            for l in range(M):
                skill[l]=skill[l]+A[k][l]

            kingaku=kingaku+C[k]
#    print("{}".format(kingaku))

    for i in range(M):
        if X>skill[i]:
            T=0

    if T==0:
        F[i]=0
    else:
        F[i]=1
        S.append(kingaku)

if min(S)==12000000:
    print("{}".format(-1))
else:
    print("{}".format((min(S))))

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**9
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(0,2**N):
    cost = 0
    know = [0]*M
    for j in range(N):
        if ((i >> j) & 1):
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
if ans==10**9:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**9
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(1,2**N):
    cost = 0
    know = [0 for z in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
if ans==10**9:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

Solution code:

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**16
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(1,2**N):
    cost = 0
    know = [0 for z in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
if ans==10**16:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**6
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(1,2**N):
    cost = 0
    know = [0 for z in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            cost+=A[j][0]
            for k in range(M):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
if ans==10**6:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**6
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(1,2**N):
    cost = 0
    know = [0 for z in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            cost+=A[j][0]
            for k in range(N):
                know[k]+=A[j][k+1]
    #print(B)
    if X<=min(know):
        ans=min(cost,ans)
if ans==10**6:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(M+1)]
ans=10**6
for i in range(N):
    A[i]=(list(map(int,input().split())))

#print(A)
for i in range(1,2**N):
    cost = 0
    know = [0 for z in range(M)]
    for j in range(N):
        if ((i >> j) & 1):
            cost+=A[j][0]
            for k in range(N):
                know[k]+=A[j][k+1]
    #print(B)
    if ans>=cost and X<=min(know) :
        ans=cost
if ans==10**6:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Runtime Error

Solution code:

import sys
from itertools import combinations

N,M,X = map(int,input().split())
CA = [list(map(int,input().split())) for _ in range(N)]
A=[0]*(M+1)

for i in range(N):
    for j in range(1,M+1):
        A[j]+=CA[i][j]

for i in range(1,M+1):
    if A[i] <X:
        print(-1)
        sys.exit()

ans=sum(A)

for i in range(1,N+1):
    for e in combinations(range(N),i):
        c = 0
        A = [0]*(M+1)
        for f in e:
            c += CA[f][0]
            for j in range(M):
                A[i] += CA[f][j+1]
        if min(A) >= X:
            ans = min(ans,c)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
n, m, x = map(int, input().split())
b = 10**18
tm = []
for i in range(m):
    tm.append(list(map(int, input().split())))
for i in range(2**n):
    c = [0 for i in range(m)]
    sum = 0
    for j in range(n):
        if (i >> j) & 1:
            sum += tm[j][0]
            for k in range(m):
                c[k] += tm[j][k+1]
    if min(c) >= x:
        b = min(b, sum)
if min == 10**18:
    print('-1')
else:
    print(b)

Submission status: Runtime Error

Solution code:
N, M, X = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
kouho = []
for i in range(2**N):
  skill = [0]*M
  price = 0
  for j in range(N):
    if ((i>>j) & 1):
      skill = [x+y for (x, y) in zip(skill, A[j][1:])]
      price += A[j][0]
  flag = 1
  for k in skill:
    if k < X:
      flag = 0
  if flag:
    kouho.append(price)
print(min(kouho))

Submission status: Runtime Error

Solution code:
A,B,C,K = map(int, input().split())
if K<=A:
    print(K)
elif A<=K<=A+B:
    print(A)
else:
    print(A-(K-A-B))
    
    
    
    
N,M,X = map(int, input().split())
CA_array = list()
for i in range(N):
    CA_list = [int(e) for e in input().split()]
    CA_array.append(CA_list)
    
ans = 13*(10**5)
    
#N<=12なので全探索しても4096.全探索する。
for i in range(2**(N)): #4096
    bit_array = str(bin(i)[2:]).zfill((N))
    #print(bit_array)

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

        if bit_array[j]=="0":
            #OFF時の処理
            pass
        elif bit_array[j]=="1":
            #ON時の処理
            for k in range(M+1): #13
                CA_on_bit_array[k] += CA_array[j][k]

    #ON・OFFの状態設定後の処理
    for k in range(1,M+1):
        if CA_on_bit_array[k] < X:
            break
    else:
        if CA_on_bit_array[0] < ans:
            ans = CA_on_bit_array[0]

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

Submission status: Runtime Error

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

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

    if li[1] >= x and li[2] >= x and li[3] >= x:
        r += [li[0]]
        
if len(r) == 0:
    print('-1')
else:
    print(min(r))

Submission status: Runtime Error

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


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


def next_book(book_list):
    global N
    global M

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

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


book_list = []
next_book(book_list)
print(min(min_can))

Submission status: Runtime Error

Solution code:
#abc_167_c
#itertools.productを使うバージョン

from itertools import product

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

INF = 1000000000000000000000000000
ans = INF


lists = list(product(list(range(2)), repeat = n))
for v in lists:
'''
for i in range(1<<n):  #n bits all searches
    # 1<<n == 2**n
'''
    c = 0
    sums = [0]*m
    for j in range(n):
        if v[j]==1:        
        '''
        if i>>j & 1: #i>>j %2 == 1  is also fine.
        '''
            #apply this candidate. 
            c += costs[j][0]
            for k in range(m):
                sums[k] += costs[j][k+1]    
                
                
    if min(sums) >= x: #if all(s>=x for s in sums) でもよい
        ans = min(ans, c)                
    '''
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)
    でもよい。
    '''
    
        
if ans==INF:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

#%%
N, M, X = [int(i) for i in input().split()]
CA = [[] for i in range(N)]
for i in range(N):
    k = list(map(int, input().split()))
    CA[i] = k[:]
CA = np.array(CA)
#%%
cnt = (10 ** 5) * N + 1

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

Submission status: Runtime Error

Solution code:
import numpy as np

#%%
N, M, X = [int(i) for i in input().split()]
CA = [[] for i in range(N)]
for i in range(M):
    k = list(map(int, input().split()))
    CA[i] = k[:]
CA = np.array(CA)
#%%
cnt = (10 ** 5) * N + 1

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

Submission status: Runtime Error

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

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

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


INF = 1000000000000000000000000000
ans = INF

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

Submission status: Runtime Error

Solution code:
# 初期入力
from itertools import permutations
import math
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_per =[i for i in range(N)]

price_list =[]
price_sum=0
N_fact = math.factorial(N)
k=0
for t in permutations(all_per): #参考書を買う順番を全列挙
    understanding =np.zeros((N ,M),dtype=int)
    understanding_method =np.zeros(M,dtype=int)
    price_sum=0
    k=0
    for i in t:
        price_sum           +=C[i][0]
        understanding[k]    =C[i][1:]
        understanding_method = np.sum(understanding, axis=0)
        k +=1
        if np.all(X <= understanding_method ): #アルゴリズム理解度が全て目標値X以上か
            price_list.append(price_sum)
            break
print(min(price_list))

Submission status: Runtime Error

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

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

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


INF = 1000000000000000000000000000
ans = INF

for i in range(1<<n):  #n bits all searches
    # 1<<n == 2**n
    c = 0
    sums = [0]*m
    for j in range(n):
        if i>>j & 1: #i>>j %2 == 1  is also fine.
            #apply this candidate. 
            c += costs[j][0]
            for k in range(m):
                sums[k] += costs[j][k+1]
    
'''
    cost = 0
    c = 0
    sums = [0] * m
    use_index=[]
    for j in range(n):
        if i%2==1:
            use_index.append(j)
        i >>= 1
    
    for v in use_index:
        c += costs[v][0]        
        for j in range(m):
            sums[j] += costs[v][j+1]
'''

    if min(sums) >= x:
        ans = min(ans, c)

'''            
    judge=True
    for j in range(m):
        if sums[j]<x:
            judge=False
            break
    
    if judge:
        ans = min(ans, c)
'''
ans = -1 if ans==INF 
print(ans)

Submission status: Runtime Error

Solution code:
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
res=F(0,[0]*len(Books[0]))
if res==float('inf'):
    print(-1)
else:
    print(res)

Submission status: Runtime Error

Solution code:
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
res=F(0,[0]*len(Books[0]))
if res=='inf':
  print(-1)
else:
  print(res)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
print(F(0,[0]*len(Books[0])))

Submission status: Runtime Error

Solution code:
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
print(F(0,[0]*len(Books[0])))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000000)
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    if (curr,tuple(prev)) in DP:
        return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
print(F(0,[0]*len(Books[0])))

Submission status: Runtime Error

Solution code:
import numpy as np

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

data = [list(map(int, input().split())) for _ in range(N)]
INF = float('int')

data_all = []
c_min = INF

for i in range(2**N):
    data_tmp = [0]*M
    c = 0
    for j in range(N):
        if((i>>j) & 1):
            for k in range(M):
                data_tmp[k] += data[j][k+1]
            c += data[j][0]
    if(min(data_tmp) >= X):
        c_min = min(c, c_min)

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

Submission status: Runtime Error

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

ans=10**7
for i in range(1<<n):
    money=0
    a=[0]*n
    for j in range(n):
        if (i>>j)%2==1:
            money+=l[j][0]
            for k in range(m):
                a[k]+=l[j][k+1]
    cnt=0
    for p in a:
        if p>=x:
            cnt+=1
    if cnt==m:
        ans=min(ans,money)
if ans==10**7:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

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

ans=10**7
for i in range(1<<n):
    money=0
    a=[0]*n
    for j in range(n):
        if (i>>j)%2==1:
            money+=l[j][0]
            for k in range(m):
                a[k]+=l[j][k+1]
    cnt=0
    for p in a:
        if p>=x:
            cnt+=1
            if cnt==m:
                ans=min(ans,money)
if ans==10**9:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

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

ans=10**9
for i in range(1<<n):
    money=0
    a=[0]*n
    for j in range(n):
        if (i>>j)%2==1:
            money+=l[j][0]
            for k in range(m):
                a[k]+=l[j][k+1]
    cnt=0
    for p in a:
        if p>=x:
            cnt+=1
            if cnt==m:
                ans=min(ans,money)
print(ans)

Submission status: Runtime Error

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

ans=10**9
for i in range(1<<n):
    money=0
    a=[0]*n
    for j in range(n):
        if (i>>j)%2==1:
            money+=l[j][0]
            for k in range(m):
                a[k]+=l[j][k+1]
    cnt=0
    for p in a:
        if p>=x:
            cnt+=1
            if cnt==m:
                ans=min(ans,money)
if ans==10**9:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

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

ans=10**9
for i in range(1,1<<n):
    money=0
    a=[0]*n
    for j in range(n):
        if (i>>j)%2==1:
            money+=l[j][0]
            for k in range(m):
                a[k]+=l[j][k+1]
    cnt=0
    for p in a:
        if p>=x:
            cnt+=1
            if cnt==m:
                ans=min(ans,money)
if ans==10**9:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

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

ans=10**9
for i in range(1,1<<n):
    money=0
    a=[0]*n
    for j in range(n):
        if (i>>j)%2==1:
            money+=l[j][0]
            for k in range(m):
                a[k]+=l[j][k+1]
    cnt=0
    for p in a:
        if p>=x:
            cnt+=1
            if cnt==m:
                ans=min(ans,money)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
i = list(map(int, input().split()))
N = i[0]
M = i[1]
X = i[2]
 
a = []
 
for _ in range(N):
    tmp = list(map(int, input().split()))
    a.append(tmp)
 
a_num = np.array(a)
 
k = 0
b = '0' + str(N) + 'b'
bit_l= []
for i in range (2 ** N):
    tmp = format(k, b)
    for j in range(N):
        bit.append(int(tmp[j]))
    
    bit_l.append(bit)
    bit = []
    k += 1
 
 
 
understand = [0]*M
understand_n = np.array(understand)
 
 
price = 0
price_min = 9999999999
 
for i in range(2 ** N):
    for j in range(N):
        if(bit_l[i][j] == 1):
            #print("i,j = ",i,j)
            #print("a_num = ",a_num[j,1:])
            understand_n += a_num[j][1:]
            #print('理解度 ',understand_n)
            price += a_num[j][0]
            #print('price ',price )
            
    #print('==============')
    if (understand_n.min() >= X) and (price < price_min):
        #print('^^^^^^^^^^^^^^')
        #print("ifのなかの理解度",understand_n)
        price_min = price
        #print("price_min ",price_min)
        #print('^^^^^^^^^^^^^^^')
    price =0
    understand_n = [0]*M
    
if price_min == 9999999999:
    print(-1)
else:
  	result = price_min.tolist()
    print(result)

Submission status: Runtime Error

Solution code:
i = list(map(int, input().split()))
N = i[0]
M = i[1]
X = i[2]
 
a = []
 
for _ in range(N):
    tmp = list(map(int, input().split()))
    a.append(tmp)
 
a_num = np.array(a)
 
k = 0
b = '0' + str(N) + 'b'
bit_l= []
for i in range (2 ** N):
    tmp = format(k, b)
    for j in range(N):
        bit.append(int(tmp[j]))
    
    bit_l.append(bit)
    bit = []
    k += 1
 
 
 
understand = [0]*M
understand_n = np.array(understand)
 
 
price = 0
price_min = 9999999999
 
for i in range(2 ** N):
    for j in range(N):
        if(bit_l[i][j] == 1):
            #print("i,j = ",i,j)
            #print("a_num = ",a_num[j,1:])
            understand_n += a_num[j][1:]
            #print('理解度 ',understand_n)
            price += a_num[j][0]
            #print('price ',price )
            
    #print('==============')
    if (understand_n.min() >= X) and (price < price_min):
        #print('^^^^^^^^^^^^^^')
        #print("ifのなかの理解度",understand_n)
        price_min = price
        #print("price_min ",price_min)
        #print('^^^^^^^^^^^^^^^')
    price =0
    understand_n = [0]*M
    
if price_min == 9999999999:
    print(-1)
else:
  	result = price_min.tolist()
    print(result)

Submission status: Runtime Error

Solution code:
n,m,x=map(int,input().split())
c=list(map(int,input().split()))
l=[]
for i in range(2**n):
    l.append(format(i,'b').zfill(n))
l1=[]
for i in range(len(l)):
    s=[0]*(m+1)
    for j in range(n):
        if l[i][j]=='1':
            for k in range(m+1):
                s[k]+=c[j][k]

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

Submission status: Runtime Error

Solution code:
N,M,X=list(map(int,input().split()))
C=[list(map(int,input().split())) for i in range(N)]
result=[]
for i in range(2**N):
    A=[]
    for j in range(N):
        if (i>>j)&1:
            A.append(C[j])
    result.append(A)
inf=float('inf')
ans2=inf

for i in result:
    D=dict()
    ans1=0
    if i!=[]:
        for j in i:
            ans1+=j[0]
            D[1]=D.get(1,0)+j[1]
            D[2]=D.get(2,0)+j[2]
            D[3]=D.get(3,0)+j[3]
            
        if (D[1]>=X) and (D[2]>=X) and (D[3]>=X):
            ans2=min(ans2,ans1)
if ans2==inf:
    print(-1)
else:
    print(ans2)