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:
def list_add(li1, li2):
    return list(map(sum,zip(li1,li2)))
N, M, X = map(int, input().split(" "))
list = []
for i in range(N):
    list.append([int(i) for i in input().split(" ")])
list.sort()
price = 0
knowledge = []
priceList = []
for i in range(N):
    price = price + list[i][0]
    if i == 0:
        knowledge = list[0][1: M + 1]
    else:
        tmp2 = [x + y for (x, y) in zip(knowledge, list[i][1:M+1])]
        knowledge = tmp2
    # 全部足しても足りないとき
    if i == N - 1 and min(knowledge) < X:
        print(-1)
        exit()
    # 目標を超えたとき
    if min(knowledge) >= X:
        for j in range(i, -1, -1):
            searchList = [x - y for (x, y) in zip(knowledge, list[j][1: M + 1])]
            if min(searchList) >= X:
                knowledge = searchList
                price = price - list[j][0]
        break
for i in range(N):
    if min(list[i][1: M + 1]) >= X and min(priceList) > list[i][0]:
        print(list[i][0])
        exit()
print(price)

Submission status: Runtime Error

Solution code:
DEBUG = False

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

if DEBUG:
    print(A)
    print(C)

ans_money = float('inf')
# ans_algorythm = None
for i in range(2**N):
    bit = bin(i)[2::]
    bit = bit.zfill(M)
    if DEBUG:
        print("i: {}, bit: {}".format(i, bit))
    tmp_money = 0
    tmp_algorythm = [0] * M
    for j, b in enumerate(bit):
        if b == '1':
            tmp_money += C[j]
            for k, c in enumerate(A[j]):
                tmp_algorythm[k] += c
    if DEBUG:
        print("tmp_money: {}, tmp_algorythm: {}".format(tmp_money, tmp_algorythm))
    if len(list(filter(lambda x: x < X, tmp_algorythm))) == 0:
        ans_money = min(tmp_money, ans_money)
        if DEBUG:
            print("ans_money: {}".format(ans_money))
        # break

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

Submission status: Runtime Error

Solution code:
n,m,x = map(int, input().split())
import numpy as np
b = []
c = []
for i in range(n):
  tmp = list(map(int, input().split()))
  b.append(tmp[1:])
  c.append(tmp[0])
skill = np.array([0 for i in range(m)])
b = np.array(b)
c = np.array(c)
ind = 0
rms = []
cos = 0
for i in range(m):
  if skill[i] < x:
    rms = []
    tmp = b[:,i]/c
    ind = np.argsort(tmp)
    for j in ind[::-1]:
      skill += b[j]
      cos += c[j]
      rms.append(j)
      if skill[j] >= x:
        np.delete(b, rms, axis=0)
        np.delete(c, rms)
        break
    
    
if all(skill >= x):
  print(cos)
else:
  print(-1)

Submission status: Runtime Error

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

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, m, x = map(int, input().split())
l=[]
for i in range(n):
    l.append(list(map(int, input().split())))
#print(l)
ans=[]
mon = [0]*(2**n)

for i in range(2**(n)):
    ans1 = 0
    ans2 = 0
    ans3 = 0
    #print(anss, mon)
    for j in range(n):
        #print(l[j][0])
        #print(i-2**(n-1))
        if ((i>>j)&1):
            mon[i-2**(n-1)]+=l[j][0]
            ans1+=l[j][1]
            ans2 += l[j][2]
            ans3+=l[j][3]
    if ans1<x:
        continue
    if ans2<x:
        continue
    if ans3<x:
        continue
    #print(ans1,ans2,ans3)
    ans.append(mon[i-2**(n-1)])

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

Submission status: Runtime Error

Solution code:
N,M,X = map(int,input().split())
list1 = [list(map(int,input().split())) for _ in range(N)]
import itertools
res = []
for con in range(N):
  for c in itertools.combinations(list1, con):
    a = [0]*(M+1)
    add = True
    for r in c:
      for i in range(len(r)):
        a[i] += r[i]
    for i in range(1,len(a)):
      if a[i] < X:
        add = False
        break
    if add:
      res.append(a)
min_ = 100000000
idx = None
for i in range(len(res)):
  if res[i][0] < min_:
    min_ = res[i][0]
    idx = i
print(res[idx][0])

Submission status: Runtime Error

Solution code:
#coding :utf-8
import numpy as np

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

suma=sum(a[0][])
print(suma,a)

Submission status: Runtime Error

Solution code:
def list_add(li1, li2):
    return list(map(sum,zip(li1,li2)))
N, M, X = map(int, input().split(" "))
list = []
for i in range(N):
    list.append([int(i) for i in input().split(" ")])
list.sort()
price = 0
knowledge = []
priceList = []
flag = True
for i in range(N):
    if flag:
        price = price + list[i][0]
        if i == 0:
            knowledge = list[0][1: M + 1]
        else:
            tmp2 = [x + y for (x, y) in zip(knowledge, list[i][1:M+1])]
            knowledge = tmp2
        # 全部足しても足りないとき
        if i == N - 1 and min(knowledge) < X:
            print(-1)
            exit()
        # 目標を超えたとき
        if min(knowledge) >= X and flag:
            for j in range(i, -1, -1):
                searchList = [x - y for (x, y) in zip(knowledge, list[j][1: M + 1])]
                if min(searchList) >= X:
                    knowledge = searchList
                    price = price - list[j][0]
            flag = False
for i in range(N):
    if min(list[i][1: M + 1]) >= X and min(priceList) > list[i][0]:
        print(list[i][0])
        exit()
print(price)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = [[int()] * (M+1) for _ in range(N)] # type: "List[int]"

    for i in range(N):
        A[i] = [int(next(tokens)) for _ in range(M+1)]
    
    # print(A)

    A = np.array(A)
    min_c = [10000000]

    def dfs(k, dep):
        if dep == N-1:
            if (k[1:]>=X).all():
                min_c[0] = min(min_c[0], k[0])
            elif (k[1:]+A[dep][1:]>=X).all():
                min_c[0] = min(min_c[0], k[0]+A[dep][0])
        else:
            dfs(k+A[dep],dep+1)
            dfs(k,dep+1)

    dfs(A[0], 1)          
    dfs(np.zeros(M+1), 1)
    
    if min_c[0] != 10000000:
        print(int(min_c[0]))
    else:
        print(-1)




if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
 
if __name__ == '__main__':
    n,m,x = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    c, a = [], np.ndarray((n,m))
 
    for i in range(n):
        ls  = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        tc, ta = ls[0], ls[1:]
        c.append(tc)
        # a.append([ta])
        a[i] = ta
 
    mini = 1000000
    indices= [list(map(lambda x:int(x), list(bin(i)[2:].zfill(m)))) for i in range(1, 2**m)]
    for idx in indices:
        ix = list(map(lambda x: x[0], filter(lambda x: x[1] == 1, enumerate(idx))))
        if all([True if r >= x else False for r in sum([a[i] for i in ix])]):
            tmini = sum([c[i] for i in ix])
            if mini > tmini:
                mini = tmini
    if mini == 1000000:
        print('-1')
    else:
        print(mini)

Submission status: Runtime Error

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

ans = 1000000000000
data = []
for i in range(n):data.append(list(map(int, input().split())))
for i in range(2**n):
    s = (5- len(bin(i)))*"0" + bin(i)[2:]
    #print(s)
    mokuhyou = []
    for i in range(m):mokuhyou.append(0)
    c = 0
    price = 0


    for i in s:
        if(i=="1"):
            price+=data[c][0]
            for i in range(m):
                mokuhyou[i] += data[c][i+1]
        c+=1

    result = True
    #print(mokuhyou)
    for i in mokuhyou:
        if(i < x):
            result = False
    if(result):ans = min(ans, price)

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

Submission status: Runtime Error

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

nls = np.array(c)
f=0
if not all(np.sum(nls, axis=0) > x):
    f = 1
    print("-1")   
else:
    import itertools
    import pprint
    result=[]
    final =[]
    for n in range(1,len(c)+1):
        for conb in itertools.combinations(c, n):
            result.append(list(conb))
    for l in result:
        l=np.array(l)
        tmp = np.sum(l, axis=0)
        # print("tmp", tmp)
        if all(tmp >= x):
            final.append(tmp.tolist())
    final.sort()
    print(final[0])[0]

Submission status: Runtime Error

Solution code:
import itertools
N,M,X =map(int,input().split())
CA =[[int(i) for i in input().split()] for j in range(N)]
lst=[]
ex=[]
kkk=[]
for k in range(N):
  lst.append(k)
  
for g in range(1,len(lst)+1):
  els =[list(x) for x in itertools.combinations(lst,g)]
  ex.extend(els)
  
for rr in ex:
  num =[0]*(M+1)
  for kz in rr:
    for o in range(M+1):
      num [o] += CA[kz][o]
  if (num[1]>=X) and (num[2]>=X )and (num[3] >=X):
    kkk.append(num[0])
    
kkk.sort()
if kkk:
  print(kkk[0])
else:
  print('-1')

Submission status: Runtime Error

Solution code:
import numpy as np


n,m,x = map(int, input().split())
lis = [np.asarray(list(map(int, input().split()))) for _ in range(n)]
lis = np.array(lis)

res = []
for i in range(2**n):
    t = np.array([0]*(m+1))
    for j in range(n):
        if ((i >> j) & 1):
            t += lis[j]
    res.append(t)

res = np.array(res)

z = 10**10

for i in res:
    if np.amin(i[1:m]) >= x and i[0] < z:
        z = i[0]

print(z if z != 10**10 else -1)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
N, M, X = map(int,input().split())

data = []
for i in range(M):
  data.append(np.array(list(map(int,input().split()))))

min = 1 << 32
for i in range(1, M):
  for j in itertools.combinations(data, i):
    temp = 0
    for k in j:
      if type(temp) == int:
        temp = np.copy(k)
      else:
        temp += k
    result = True
    if min > temp[0]:
      for k in temp[1:]:
        if k < X:
          result = False
          break
      if result: 
        min = temp[0]

print(-1 if min == 1 << 32 else min)

Submission status: Runtime Error

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

rikai = np.zeros(M)
price = 0
i = 0
while np.min(rikai) < X:
    rikai += A[i]
    price += C[i]
    i += 1

switch = np.zeros(N)
for i in range(1,2**N):
    rikai = np.zeros(M)
    for j in range(N):
        if (i>>j)&1:
            switch[j] = 1
            rikai += A[i]
    if np.min(rikai) >= X:
        temp_price = C*switch
        if temp_price < price:
            price = temp_price
    switch = np.zeros(N)
print(temp_price)

Submission status: Runtime Error

Solution code:
n, m, x = map(int, input().split())
text_list = [[int(_) for _ in input().split()] for _ in range(n)]
ans = -1
a_all = []
ans_list = []
a_all_=[]
for i in text_list:
    print(i)
    a_all += i

if a_all[1]<x or a_all[2]<x or a_all[3]<x:
    print(ans)


def judge(a, a_all_):
    if a[1]<x or a[2]<x or a[3]<x:
        ans_list.append(a)
    if a_all_[1]<x or a_all_[2]<x or a_all_[3]<x:
        ans_list.append(a_all_)
        

for i1 in range(n):
    a = text_list[i1]
    a_all_ = a_all+-1*a
    judge(a, a_all_)

for i1 in range(n-1):
    for i2 in range(i1, n):
        a = text_list[i1]+text_list[i2]
        a_all_ = a_all+-1*a
        judge(a, a_all_)
        
for i1 in range(n-2):
    for i2 in range(i1, n-1):
        for i3 in range(i2, n):
            a = text_list[i1]+text_list[i2]+text_list[i3]
            a_all_ = a_all+-1*a
            judge(a, a_all_)
            
for i1 in range(n-3):
    for i2 in range(i1, n-2):
        for i3 in range(i2, n-1):
            for i4 in range(i3, n):
                a = text_list[i1]+text_list[i2]+text_list[i3]+text_list[i4]
                a_all_ = a_all+-1*a
                judge(a, a_all_)

for i1 in range(n-4):
    for i2 in range(i1, n-3):
        for i3 in range(i2, n-2):
            for i4 in range(i3, n-1):
                for i5 in range(i4, n):
                    a = text_list[i1]+text_list[i2]+text_list[i3]+text_list[i4]+text_list[i5]
                    a_all_ = a_all+-1*a
                    judge(a, a_all_)

for i1 in range(n-5):
    for i2 in range(i1, n-4):
        for i3 in range(i2, n-3):
            for i4 in range(i3, n-2):
                for i5 in range(i4, n-1):
                    for i in range(i5, n):
                        a = text_list[i1]+text_list[i2]+text_list[i3]+text_list[i4]+text_list[i5]
                        a_all_ = a_all+-1*a
                        judge(a, a_all_)

ans_list.sort()
print(ans_list[0][0])

Submission status: Runtime Error

Solution code:
import numpy as np
N,M,X = map(int, input().split())
nd_list = np.ones(M)*X

next_list = []
for i in range(0,N):
    next_list.append(list(map(int, input().split())))
next_list = np.array(next_list)
min_tot = 10000000

def dfs(i,ab_list):
    global min_tot
    if i==N and np.all(ab_list[1:]>=nd_list):
        if min_tot > ab_list[0]:
            min_tot = ab_list[0]
        return True
    elif i ==N:
        return True

    dfs(i+1,ab_list)
    dfs(i+1,ab_list+next_list[i,:])


if min_tot ==10000000:
    print(-1)
else:
    print(min_tot)

Submission status: Runtime Error

Solution code:
import numpy as np

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


min=-1
for nnn in range(2**n):
    index=[]
    a=nnn
    for i in range(n):
        index.append(a%2)
        a//=2

    money=0
    xs=np.zeros(n)
    for i in range(n):
        if index[i]==1:
            money+=lis[i][0]
            xs+=np.array(lis[i][1:])
    if np.amin(xs)>=x:
        if min==-1:
            min=money
        elif min>money:
            min=money
print(min)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(N+1)]
ans=10**5
for i in range(N):
    A[i]=(list(map(int,input().split())))
A=np.array(A)
#print(A)
for i in range(2**N):
    B=np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            B+=A[j]
    #print(B)
    if not B.all(0):
         continue
    elif ans>=B[0] and X<=min(B[1:M]):
        ans=B[0]
if ans==100000:
    print(-1)
    exit()
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
N, M, X = map(int,input().split())

data = []
for i in range(M):
  data.append(np.array(list(map(int,input().split()))))

min = 1 << 32
for i, _ in enumerate(data, 1):
  for j in itertools.combinations(data, i):
    temp = 0
    for k in j:
      if type(temp) == int:
        temp = np.copy(k)
      else:
        temp += k
    print(temp)
    result = True
    if min > temp[0]:
      for k in temp[1:]:
        if k < X:
          result = False
          break
      if result: 
        min = temp[0]

print(-1 if min == 1 << 32 else min)

Submission status: Runtime Error

Solution code:
import numpy as np


n,m,x = map(int, input().split())
lis = [np.asarray(list(map(int, input().split()))) for _ in range(n)]
lis = np.array(lis)

res = []
for i in range(2**n):
    t = np.array([0]*(n+1))
    for j in range(n):
        if ((i >> j) & 1):
            t += lis[j]
    res.append(t)

res = np.array(res)

z = 10**10

for i in res:
    if np.amin(i[1:m]) >= x and i[0] < z:
        z = i[0]

print(z)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, X = map(int,input().split())

data = []
for i in range(M):
  data.append(np.array(list(map(int,input().split()))))

min = 1 << 32
for i, _ in enumerate(data, 1):
  for j in itertools.combinations(data, i):
    temp = 0
    for k in j:
      if type(temp) == int:
        temp = np.copy(k)
      else:
        temp += k
    print(temp)
    result = True
    if min > temp[0]:
      for k in temp[1:]:
        if k < X:
          result = False
          break
      if result: 
        min = temp[0]

print(-1 if min == 1 << 32 else min)

Submission status: Runtime Error

Solution code:
from numpy import array

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


c=[]
d=[0]*(m+1)
for i in range(n):
    c1=array(list(map(int,input().split())))
    c.append(c1)
    d+=c1

#print(c)
c.sort(key=lambda x: x[0], reverse=True)
#print(c)
#print(d)

if(False in [x<=i for i in d[1:]]):
   print(-1)
   exit()

#print(d[0])

for i in range(n):
    e=d-c[i]
    #print(e)
    if(False not in [x<=i for i in e[1:]]):
        d=e

print(d[0])

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
for i in range(N - 1):
    d = list(map(int, input().split()))
    CA = np.vstack((CA,d))
C = CA[:,0]
A = CA[:,1:]

S = [0] * M
for i in range(M):
    S[i] = np.sum(A[:,i])
index = np.argmin(S)
if len(index) > 1:
    index = index[0]
if S[index] < X:
    print(-1)
else:
    print(100)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(N+1)]
ans=10**5
for i in range(N):
    A[i]=(list(map(int,input().split())))
A=np.array(A)
#print(A)
for i in range(2**N):
    B=np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            B+=A[j]
    #print(B)
    # if B==[]:
    #     continue
    if ans>=B[0] and X<=min(B[1:M]):
        ans=B[0]
if ans==100000:
    print(-1)
    exit()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import itertools
import numpy as np


if __name__ == '__main__':
    # BM}2rEY$rxB0J>e$K$7$?$$
    n,m,x = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    c, a = [], np.ndarray((n,m))

    for i in range(n):
        ls  = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        tc, ta = ls[0], ls[1:]
        c.append(tc)
        # a.append([ta])
        a[i] = ta

    mini = 1000000
    indices= [list(map(lambda x:int(x), list(bin(i)[2:].zfill(m)))) for i in range(1, 2**m)]
    for idx in indices:
        ix = list(map(lambda x: x[0], filter(lambda x: x[1] == 1, enumerate(idx))))
        if all([True if r >= 10 else False for r in sum([a[i] for i in ix])]):
            #print(sum([a[i] for i in ix]), sum([c[i] for i in ix]))
            tmini = sum([c[i] for i in ix])
            if mini > tmini:
                mini = tmini
    if mini == 1000000:
        print('-1')
    else:
        print(mini)

Submission status: Runtime Error

Solution code:
import numpy as np
import copy
N, M, X = map(int, input().split())
C = np.zeros(N, dtype=np.int64)
A = np.zeros([N, M], dtype=np.int64)
skills = np.zeros(M, dtype=np.int64)
sum_skills = np.zeros(M, dtype=np.int64)
sum_A = np.zeros(N, dtype=np.int64)

for n in range(N):
    CA = list(map(int, input().split()))
    C[n] = CA[0]
    A[n] = CA[1:]
    sum_skills += CA[1:]
    sum_A[n] = sum(CA[1:])


def check_skills(skills):
    return np.all(skills >= X)


if np.all(sum_skills >= X):
    pass
else:
    print("-1")
    exit()

results = []
book_sorted = np.argsort(sum_A)
for n in range(M):
    result = ([n], C[n].copy(), A[n].copy())
    results.append(result)

min_cost = np.sum(C)

while len(results) > 0:
    result = results.pop(0)
    if check_skills(result[2]):
        min_cost = min(min_cost, result[1])
    else:
        max_idx = max(result[0])
        for idx in range(max_idx+1, N):
            (idxes, total_cost, skill_values) = copy.copy(result)
            idxes = idxes + [idx]
            total_cost = total_cost + C[idx]
            skill_values = skill_values + A[idx]
            results.append((idxes, total_cost, skill_values))

print(min_cost)

Submission status: Runtime Error

Solution code:
import itertools

nums = [int(e) for e in input().split()]

list0 = []
for i in range(0, nums[0]):
    val = [int(e) for e in input().split()]
    list0.append(val)

A = []
A0 = list(range(0,nums[0]))
for x in itertools.combinations_with_replacement(A0,nums[0]):
    A1 = list(x)
    A1 = list(set(A1))
    A.append(A1)


X = []
for i in range(0,len(A)):
    Y = [0] * (nums[1]+1)
    for j in range(0,len(A[i])):
        Y = [x + y for (x, y) in zip(Y,list0[A[i][j]])]
    X.append(Y)

B = []
for i in range(0,len(X)):
    if X[i][1] >= nums[2] and X[i][2] >= nums[2] and X[i][3] >= nums[2]:
        B.append(X[i][0])

if len(B) > 0:
    print(min(B))
else:
    print('-1')

Submission status: Runtime Error

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

temp_all = []
s = [X]*M
temp_all = [list(map(int, input().split())) for _ in range(N)]
ans = 0
book  = N
while sum(s) != 0:
    if book == 0:
        ans = -1
        break
    min_value = 10 ** 5
    for n in range(book):
        temp = temp_all[n]
        value = temp[0]/sum([min(t, x) for x, t in zip(s, temp[1:])])
        if value < min_value:
            min_value = value
            min_index = n

    s = [max(0, x - t) for x, t in zip(s, temp_all[min_index][1:])]
    ans += temp_all[min_index][0]
    book -= 1
    del temp_all[min_index]

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations

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

# print(cost_lists)

min_cost = 10**9
unst_flag = False

for i in range(1, n+1):
    combi_lists = list(combinations(range(n), i))

    for combi_list in combi_lists:
        tmp_list = list()
        for j in range(1,m):
            tmp_unst = 0
            for k in combi_list:
                tmp_unst += cost_lists[k][j]

            tmp_list.append(tmp_unst)
        
        if min(tmp_list) >= x:
            tmp_cost = 0
            for k in combi_list:
                tmp_cost += cost_lists[k][0]

            min_cost = min(min_cost, tmp_cost)
            unst_flag = True

if unst_flag:
    print(min_cost)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
(n, m, x) = tuple(map(int, input().split(" ")))
ca = [list(map(int, input().split(" "))) for i in range(n)]
c = -1
for i in range(n):
    itr = itertools.combinations(ca, i + 1)
    for v in itr:
        cv = np.array(v).sum(axis=0)
        if (cv[1:m] >= x).all() and (c == -1 or cv[0] < c):
            c = cv[0]
assert(c!=-1)
print(c)

Submission status: Runtime Error

Solution code:
import itertools


def main():
    n, m, x = input_list()

    costs = []
    contents = [[] for i in range(m)]
    contents_with_index = [[] for i in range(m)]
    for i in range(n):
        b = input_list()
        costs.append(b[0])
        for index, c in enumerate(b[1:]):
            contents[index].append(c)
            contents_with_index[index].append((i, c))

    for c in contents:
        if sum(c) < x:
            print(-1)
            exit()

    results = [[] for i in range(m)]
    for index, c in enumerate(contents_with_index):
        for i in range(2, m+1):
            for cv in itertools.combinations(c, i):
                s = sum([num[1] for num in cv])
                if s >= x:
                    results[index].append([num[0] for num in cv])
    ans = []
    for r in results[0]:
        is_continue = False
        for v in results:
            if has(r, v) is False:
                is_continue = True
                break
        if is_continue:
            continue

        ans.append(r)

    usable_cost = []
    for a in ans:
        usable_cost.append(sum(list(map(lambda x: costs[x], a))))

    print(min(usable_cost))


def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np
#S= str(input())
#T= str(input())
N,M,X = map(int,input().split())
#N = int(input())
#A = list(map(int,input().split()))
a=[]
c=[]
ans=[]
for j in range(N):

    A = list(map(int,input().split()))
    c.append(A)
    a.append(A)

for i in range(1,N+1):
    for l in list(combinations(a,i)):
        s=np.zeros(M+1)
        for k in l:
            k=np.array(k)
            s=s+k
        #print(s)
        
        if min(s)>=X:
            ans.append(s[0])
print(int(min(ans)))

Submission status: Runtime Error

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(N+1)]
ans=10**5
for i in range(N):
    A[i]=(list(map(int,input().split())))
A=np.array(A)
#print(A)
for i in range(2**N):
    B=np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            B+=A[j]
    #print(B)
    if B==[]:
        continue
    elif ans>=B[0] and X<=min(B[1:M]):
        ans=B[0]
if ans==100000:
    print(-1)
    exit()
print(ans)

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**6
b = False

for i in range(2 ** N):
    bag = []
    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 itertools
N,M,X = map(int,input().split())
book =[]
for x in range(N):
    A_list =  list(map(int, input().split()))
    book.append(A_list)
conbination =[]
for i, _ in enumerate(book, 1):     
    for j in itertools.conbination(book, r=i):  # rには1、2、3と渡される
        conbination.append(j)
minn =100000000
for x in conbination:
    A = [0]*M
    m = 0
    for y in x:
        for z in range(len(y)):
            if z ==0:
                m +=y[z]
            else:
                A[z-1] +=y[z]
    if minn >m and X<=min(A):
        minn =m
        
if minn != 100000000:
    print(minn)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
for i in range(N - 1):
    d = list(map(int, input().split()))
    CA = np.vstack((CA,d))
C = CA[:,0]
A = CA[:,1:]

S = [0] * M
for i in range(M):
    S[i] = np.sum(A[:,i])
index = np.argmin(S)
if S[index] < X:
    print(-1)
else:
    print(100)

Submission status: Runtime Error

Solution code:
import collections
import numpy as np
import sys
sys.setrecursionlimit(10**8)
N,M,X=map(int,input().split())
A=[[]for i in range(N+1)]
ans=10**5
for i in range(N):
    A[i]=(list(map(int,input().split())))
A=np.array(A)
#print(A)
for i in range(2**N):
    B=np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            B+=A[j]
    #print(B)
    if B==[]:
        continue
    elif ans>=B[0] and X<=min(B[1:M]):
        ans=B[0]
if ans==100000:
    print(-1)
    exit()
print(ans)
#N=int(input())

# h=np.array(list(map(int,input().split())))
# ans=0
# def sol(l,m,k):
#     global ans
#     if m==0:
#         return ans
#     elif m>0:
#         for i in range(N-m+1):
#             if not 0 in l[i:i+m]:
#                 ans+=np.amin(l[i:i+m])
#                 l[i:i+m]=l[i:i+m]-min(l[i:i+m])
#                 print(l)
#         sol(l,m-1,ans)
#     # else:
#     #     ans+=np.count_nonzero(h)
#     #     sol(l, m - 1, ans)
# n=0
# sol(h,N,ans)
# print(ans)

Submission status: Runtime Error

Solution code:
def mips():
    return map(int,input().split())
def msps():
    return map(str,input().split())

import sys
import itertools
N,M,X = mips()
know = dict()
price = [[] for _ in range(N)]
A = [[] for _ in range(M)]
L = []
C = []
for i in range(M):
    know[i] = 0
for i in range(N):
    L.append([i for i in mips()])
    C.append(L[i][0])
    L[i].remove(L[i][0])
for i in range(N):
    for k in range(M):
        A[k].append(L[i][k])
Money = []
paid = 0 
K = []
No = 0
P = []
Q = [i for i in range(N)]
for i in range(N):
    P.append(list(itertools.combinations(Q,i)))
for k in range(N):
    for el in P[k]:
        for book in el:
            K = L[book]
            paid += C[book]
            for i in range(M):
                know[i] += K[i]
        for i in range(M):
            if know[i] < X:
                No = 1
                break
        if No == 0:
            Money.append(paid)
        paid = 0
        No = 0
        for i in range(M):
            know[i] = 0
print(min(Money))

Submission status: Runtime Error

Solution code:
import itertools
n,m,x=map(int,input().split())
lists=[]
array=[0,0,0,0]
ans=[]
for i in range(n):
    lists.append(list(map(int,input().split())))
for i in range(n):
    for pair in itertools.combinations(lists,i+1):
        for j in range(len(pair)):
            array=list(map(lambda x,y: x+y,array,list(pair[j])))
        for k in range(m):
            if array[k+1]<x:
                break
            else:
                ans.append(array[0])
        array=[0,0,0,0]
print(min(ans) if ans else "-1")