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 sys #追加
sys.setrecursionlimit(10*7)
 
def bit_fullsearch(target):
    n = len(target)
    ret = []
    for i in range(2**n):
        tmp = []
        for j in range(n):
            if (i>>j)&1:
                tmp.append(target[j])
        ret.append(tmp)
    return ret

n,m,x = map(int,input().split())
choice = [i for i in range(n)]
l = [list(map(int,input().split())) for _ in range(n)]
ans = float('inf')
for lst in bit_fullsearch(choice):
    tmp = 0
    A = [0 for _ in range(m)]
    if len(lst)==0:
        continue
    elif len(lst)==1:
        tmp = l[0]
        j = lst[0]
        for k in range(m):
            A[k] += l[j][1+k]
    else:
        for j in lst:
            tmp += l[j][0]
            for k in range(m):
                A[k] += l[j][1+k]
    if min(A) >= x:
        ans = min(ans, tmp)
print(ans if ans!=float('inf') else -1)

Submission status: Runtime Error

Solution code:
N,M,X=map(int,input().split())
s=[list(map(int,input().split())) for i in range(N)]
t=sum(s)
for i in range(1,M+1):
  if t[i]<10:
    print(-1)
    break

Submission status: Runtime Error

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


print(List)
flag=True
i=1
champ=100000
total_cost=100000
while flag:
    newlist=list(itertools.combinations(range(N),i))
    for j in range(len(newlist)):
        for s in range(1,M+1):
            if sum(List[t][s] for t in newlist[j])<X:
                flag2=False
                break
        if flag2!=False:    
            total_cost=sum(List[t][0] for t in newlist[j])
        if total_cost<champ:
            champ=total_cost
        flag2=True
    if champ!=100000:
        print(champ)
        flag=False
        break
    i=i+1
    if i==N+1:
        break

if flag:    
    print(-1)

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('-1')
else:
    print(min(B))

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:]

C_set = []
for i in range(2 ** (M+1)):
    book = format(i, '0'+str(N)+'b')
    S = [0] * M
    CC = 0
    for j in range(M):
        if book[j] == "1":
            S = S + A[j,:]
            CC += C[j]
    if np.min(S) > X:
        C_set.append(CC)
if len(C_set) == 0:
    print(-1)
else:
    print(np.min(C_set))

Submission status: Runtime Error

Solution code:

N,M,X = map(int,input().split(" "))
# N冊、Xは目標値
CAList = []
for i in range(N):
    ca = list(map(int,input().split(" ")))
    CAList.append(ca)
CAList = sorted(CAList, key=lambda x: x[0]/sum(x[1:]))

resultList = [0] * (M+1)
found = False
for a in CAList:
    resultList = [x + y for (x, y) in zip(resultList, a)]
    if min(resultList[1:]) >= X:
        print(resultList[0])
        found = True
        break

if not found:
    print("-1")

Submission status: Runtime Error

Solution code:
N,M,X = map(int,input(),split())
C = [input().split() for i in range(N)]
A = [input().split() for j in range(N)]
t =1

for l in range(N):
  g = 0
  for m in range(M):
    g += A[l][m]
  if g <10:
    t*=0
  else:
    t*=1

if t ==0:
  print(-1)
else:
  print(0)

Submission status: Runtime Error

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

arr = [list(map(int, input().split())) for i in range(N)]
arr = np.array(List)
sum_arr = np.sum(arr, axis=0)
if(all(sum_arr[1:]>=X)):
  pass
else:
  print(-1)

Submission status: Runtime Error

Solution code:
import pandas as pd

Submission status: Runtime Error

Solution code:
#C
import numpy as np
flg = True
n,m,x = map(int,input().split())
algo = []
tmp = []
for _ in range(n):
    algo.append(list(map(int,input().split())))
    

algo_n = np.array(algo)
algo_sum = algo_n.sum(axis=0)
gokei = algo_sum.tolist()
money = gokei[0]
gokei = gokei[1:]

#チェックする
for i in range(m):
    if gokei[i] < x:
        flg = False
        print(-1)
        break

algo.sort(key= lambda x:x[0],reverse=True)

#print(algo)
#print(gokei)
# 計算用の関数
def hikizan(lst1,lst2):
#lst1 - lst2
    lst_ans = [0 for _ in range(len(lst1))]
    for i in range(len(lst1)):

        l1 = lst1[i]
        l2 = lst2[i]
        l1 -= l2
        lst_ans[i] = l1
    return lst_ans

def check_lst(lst1,target):
    for i in range(len(lst1)):
        if lst1[i] < target:
            return False
        
    return True

if flg:
    for k in range(n):
        gokei_t = gokei
        money_t = money
        for i in range(k,n):
            if check_lst(hikizan(gokei_t,algo[i][1:]),x):

                gokei_t = hikizan(gokei_t,algo[i][1:])
                money_t -= algo[i][0]
            
            
        tmp.append(money_t)
            
            
 

print(min(tmp))

Submission status: Runtime Error

Solution code:
def bit_fullsearch(target):
    n = len(target)
    ret = []
    for i in range(2**n):
        tmp = []
        for j in range(n):
            if (i>>j)&1:
                tmp.append(target[j])
        ret.append(tmp)
    return ret

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

ans = float('inf')
for lst in bit_fullsearch(choice):
    tmp = 0
    A = [0 for _ in range(m)]
    if len(lst)==0:
        continue
    elif len(lst)==1:
        tmp = l[0]
        j = lst[0]
        for k in range(m):
            A[k] += l[j][1+k]
    else:
        for j in lst:
            tmp += l[j][0]
            for k in range(m):
                A[k] += l[j][1+k]
    if min(A) >= x:
        ans = min(ans, tmp)
print(ans if ans!=float('inf') else -1)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = [i-1 for i in list(map(int, input().split()))]

l = []
used = [0 for _ in range(n)]

c = 0
flag = True
while 1:
    if not flag:
        l.append(c)
    if used[c] == 1 and l:
        break
    if not flag:
        used[c] = 1
    c = a[c]
    flag = False

p = 0
length = len(l)
b = []
for i in range(length):
    if l[i] == l[-1]:
        l = l[i:-1]
        b = l[:i]
        p = i
        break

if len(b) >= k:
    print(b[k - 1])
else:
    print(l[(k - p - 1) % len(l)] + 1)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

N,M,X=map(int,input().split())
index=[i for i in range(N)]
CA=[]
sumlist=[]
for i in range(N):
    CA.append([int(j) for j in input().split()])
CA=np.array(CA)
CAsum=np.sum(CA,axis=0)
if(np.size(np.where(CAsum[1:len(CAsum)]>=X))<M):
    print(-1)
else:
    for i in range(1,N):
        idx=list(itertools.combinations(index,i))
        for j in range(len(idx)):
            CAsum=np.sum(CA[idx[j],:],axis=0)       
            if(np.size(np.where(CAsum[1:len(CAsum)]>=X))==M):
                sumlist.append(CAsum[0])
    print(min(sumlist))

Submission status: Runtime Error

Solution code:
#import numpy as np
import math
#from fractions import gcd

def fnc(current_C_sum,current_C_set,X):

    min_money = []
    for c in range(len(current_C_set)):
        removed_C_set = current_C_set[:c]+current_C_set[c+1:]
        subtring_C_sum = current_C_sum[:]
        check_X = 0
        for m in range(len(removed_C_set[0])):
            subtring_C_sum[m] = subtring_C_sum[m] - current_C_set[c][m]
            if m!=0:
                if subtring_C_sum[m]<X:
                    check_X = -1
                    break
        if check_X!=-1:
            min_money.append(subtring_C_sum[0])
            if len(removed_C_set)>=2:
                min_money = min_money+fnc(subtring_C_sum,removed_C_set,X)

    return min_money


def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    N = first_input[0]
    M = first_input[1]
    X = first_input[2]

    C_set = []
    for n in range(N):
        second_input = list(map(lambda x:int(x), input().split(" ")))
        C_set.append(second_input)

    C_sum = [0]*(M+1)
    for n in range(N):
        for m in range(M+1):
            C_sum[m] = C_sum[m] + C_set[n][m]

    min_money = fnc(C_sum,C_set,X)

    if len(min_money)==0:
        print(-1)
    else:
        print(min(min_money))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = [i-1 for i in list(map(int, input().split()))]

l = []
used = [0 for _ in range(n)]

c = 0
flag = True
while 1:
    if not flag:
        l.append(c)
    if used[c] == 1 and l:
        break
    if not flag:
        used[c] = 1
    c = a[c]
    flag = False

p = 0
length = len(l)
b = []
for i in range(length):
    if l[i] == l[-1]:
        l = l[i:-1]
        b = l[::i]
        p = i
        break

if len(b) >= k:
    print(b[k - 1])
else:
    print(l[(k - p - 1) % len(l)] + 1)

Submission status: Runtime Error

Solution code:
N,M,X=input().split(" ")
multilist = [[0] * 12 for row in range(13)]
sum=0
sumlist=[]
flag=0
for i in range(0,int(N)):
    temp=input().split(" ")
    for j in range(0,int(M)+1):
        multilist[i][j]=temp[j]
for i in range(1,int(M)+1):
    part=0
    for j in range(0,int(N)):
        part=part+int(multilist[j][i])
    sumlist.append(part)
    if part<int(X):
        print(-1)
        flag=1
        break
if flag==0:
    for i in range(0,int(N)):
        sum=sum+int(multilist[i][0])
    for j in range(0,int(N)):
        flag=1
        tp=0
        max=int(multilist[0][0])
        for i in range(0,int(N)-j):
            if max<int(multilist[i][0]):
                max=int(multilist[i][0])
                tp=i
        for k in range(0,int(M)):
            if sumlist[k]-int(multilist[tp][k+1])<int(X):
                flag=0
                break
        if flag==1:
            for k in range(0, int(M)):
               sumlist[k]=sumlist[k] - int(multilist[tp][k + 1])
            sum=sum-int(multilist[tp][0])
        multilist.remove(multilist[tp])

    print(sum)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
import pprint
import itertools

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n, m, x = map(int, sys.stdin.readline().split())
	c = []
	a = []
	for i in range(n):
		ci, *ai = map(int, sys.stdin.readline().split())
		c.append(ci)
		a.append(ai)
	ans = 10**9
	for i in range(2**n):
		cost = 0
		rikai = [0]*n
		case = []
		for j in range(n):
			case.append(i>>j & 1)
		for j in range(n):
			if not case[j]:
				continue
			cost += c[j]
			for k in range(m):
				rikai[k] += a[j][k]
		log.print(case, rikai, len(list(filter(lambda z:z>=x, rikai))))
		if len(list(filter(lambda z:z>=x, rikai))) == m:
			ans = min(cost, ans)
	if ans == 10**9:
		print(-1)
		exit()
	print(ans)





main()

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((str(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(1, m+1):
            for cv in itertools.combinations(c, i):
                s = sum([num[1] for num in cv])
                if s >= x:
                    results[index].append(','.join([num[0] for num in cv]))
    ans = set(results[0])
    for r in results:
        ans &= set(r)

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

    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:
def minculc(C,A, Ml, X):
    ret = -1
    reti = list()
    for l in Ml:
        a = 0
        c = 0
        for i in range(len(l)):
            a += A[i] * l[i]
            c += C[i] * l[i]
        if a >= X:
            if ret == -1 or c < ret:
                ret = c
                reti.append(l)
    return reti


def makelist(N, l):
    if N == 0:
        return [l]
    else:
        l1 = l.copy()
        l2 = l.copy()
        l1.append(0)
        l2.append(1)
        ret = makelist(N-1,l1)
        ret2 = makelist(N-1, l2)
        ret = ret.copy()
        ret.extend(ret2)
        return ret

N,M,X = map(int, input().split())
C = list()
A = list()
for i in range(N):
    tmp_ = list(map(int,input().split()))
    C.append(tmp_[0])
    A.append(tmp_[1:])
l = list()
Ml = makelist(M,l)
lcost = list()
for i in range(M):
    a = list()
    for j in range(N):
        a.append(A[j][i])
    ret_ = minculc(C,a,Ml,X)
    lcost.append(ret_)

lcost.sort(key=lambda x: len(x))
retlist = list()
for i in range(len(lcost[0])):
    for j in range(len(lcost)):
        if lcost[0][i] not in lcost[j]:
            break
        if j == len(lcost)-1:
            retlist.append(lcost[0][i])
ret = -1
if len(retlist) > 0:
    for r in retlist:
        c = 0
        for i in range(len(r)):
            c += C[i] * r[i]
        if ret == -1 or c < ret:
            ret = c
print(ret)

Submission status: Runtime Error

Solution code:
import numpy as np
N,M,X = map(int,input().split())
datas = []
point = [0]*M
m = 0
max = 0
count = 0
for i in range(N):
    datas.append(list(map(int,input().split())))
print(datas)
while 1:
    for data in datas:
        if sum(data[1:-1]) > max:
            ans = count
            max = sum(data[1:-1])
        count += 1
    for i in range(M):
        point[i] += datas[ans][i+1]
    m += datas[ans][0]
    if all([x >= 10 for x in point]):
        print(m)
        break
    datas.pop(ans)
    if len(datas) == 0:
        print(-1)
        break
    max,ans,count = 0,0,0

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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

lis_C = np.array(list(map(lambda x: x[0], lis_all)))
lis_A = np.array(list(map(lambda x: x[1:], lis_all)))

row_idx = []
bools = [True,False]
for boollis in itertools.product(bools, repeat=M):
    row_idx.append(list(boollis))

c_min = lis_C.sum()+100
for i in range(len(lis_idx)):
    if all(lis_A[row_idx[i]].sum(axis=0) >= X):
        c_min = min(lis_C[row_idx[1]].sum(), c_min)
if c_min > lis_C.sum():
    ans = -1
else :
    ans = c_min
print(ans)

Submission status: Runtime Error

Solution code:
n, m, x = list(map(int,input().split()))
c = []
a = []
for i in range(n):
  a0 = list(map(int,input().split()))
  c.append(a0[0])
  a.append(a0[1:m])
  
comp = [[0] * m for i in range(2 ** n)]
price = [0] * (2 ** n)
k = 0

def calculation(int i):
  global comp
  global price
  global k
  for j in range(m):
    comp[k, j] = a[i, j]
  price[k] += c[i]
  k += 1
  calculation(i + 1)
  k += 1
  calculation(i + 1)
  
calculation(0)
answer = max(price)
for i in range(2 ** n):
  if min(comp[i, *]) >= x:
    answer = min(answer, price[i])
print(answer)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np

N,M,X=map(int, input().split())
list_=[list(map(int, input().split())) for _ in range(N)]
gokei=X
cost=100001
list_C=[]

for i in range(N):
	list_C=np.array(list(combinations(list_,N-i)))
	count=0
	for h in range(len(list_C)):

		if all(np.sum(list_C[h], axis=0)[1:]>=X) and np.sum(list_C[h], axis=0)[0]<cost:
				cost=np.sum(list_C[h], axis=0)[0]
				count+=1

		if count==0:
		break

print(cost if cost<100001 else -1)

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)

max_money = 10**5 * N
ans_money = max_money
# 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 == max_money:
    print(-1)
else:
    print(ans_money)

Submission status: Runtime Error

Solution code:
from itertools import combinations_with_replacement
n,m,x=map(int,input().split())
l=[0,1]
hon=list(combinations_with_replacement(l,n))

c=[]
a=[]

ans=1001001001

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

for i,k in enumerate(hon):
  skill=[0 for i in range(m)]
  cost=0
  flag=True
  for j in range(m):
    if k[j]==1:
      for _ in range(m):
        skill[_]+=a[j][_]
      cost+=c[j]
  for j in range(m):
    if skill[j]<x:
      flag=False
      break
  if flag:
    ans=min(ans,cost)
if ans==1001001001:
  ans=-1
print(ans)

Submission status: Runtime Error

Solution code:
import copy
from collections import Counter

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

cc = 0
MM = 0
for ca in CA:
    cc += ca[0]

    if MM < max(ca[1:]):
        MM = max(ca[1:])

U = 10**5 * cc + 1

dp = []
for i in range(M):
    p_dp = [U for _ in range(MM * M + 1)]
    p_dp[0] = 0
    dp.append(p_dp)

for ca in CA:
    c = ca[0]
    a = ca[1:]

    for i, v in enumerate(a):
        p_dp = copy.deepcopy(dp)
        for j in range(MM * M + 1 - v):
            if dp[i][j] < U:
                dp[i][j + v] = min(p_dp[i][j + v], p_dp[i][j] + c)

ans_list = list(set(dp[0][X:]))

for i in range(1, M):
    ans_list = list(set(ans_list) & set(dp[i][X:]))

print(min(ans_list) if min(ans_list) < U else -1)

Submission status: Runtime Error

Solution code:
def minculc(C,A, Ml, X):
    ret = -1
    reti = list()
    for l in Ml:
        a = 0
        c = 0
        for i in range(len(l)):
            a += A[i] * l[i]
            c += C[i] * l[i]
        if a >= X:
            if ret == -1 or c < ret:
                ret = c
                reti.append(l)
    return reti


def makelist(N, l):
    if N == 0:
        return [l]
    else:
        l1 = l.copy()
        l2 = l.copy()
        l1.append(0)
        l2.append(1)
        ret = makelist(N-1,l1)
        ret2 = makelist(N-1, l2)
        ret = ret.copy()
        ret.extend(ret2)
        return ret

N,M,X = map(int, input().split())
C = list()
A = list()
for i in range(N):
    tmp_ = list(map(int,input().split()))
    C.append(tmp_[0])
    A.append(tmp_[1:])
l = list()
Ml = makelist(M,l)
lcost = list()
for i in range(M):
    a = list()
    for j in range(N):
        a.append(A[j][i])
    ret_ = minculc(C,a,Ml,X)
    lcost.append(ret_)

lcost.sort(key=lambda x: len(x))
retlist = list()
for i in range(len(lcost[0])):
    for j in range(len(lcost)):
        if lcost[0][i] not in lcost[j]:
            break
        if j == len(lcost)-1:
            retlist.append(lcost[0][i])
ret = -1
for r in retlist:
    c = 0
    for i in range(len(r)):
        c += C[i] * r[i]
    if ret == -1 or c < ret:
        ret = c
print(ret)

Submission status: Runtime Error

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

cc_ = []
for i in range(n):
    cc_.append(c_[i][0])
# print(cc_)

import numpy as np
import itertools
l = np.arange(n)

res1_ = []
res2_ = []
res3_ = []
cc_r_ = []
resList = []
flag = False
for i in range(2,n+1):
    c = list(itertools.combinations(l, i))
    for j in c:
        # print(j)
        res1_ = []
        res2_ = []
        res3_ = []
        cc_r_ = []
        for k in range(len(j)):
            res1_.append(c_[j[k]][1])
            res2_.append(c_[j[k]][2])
            res3_.append(c_[j[k]][3])
            cc_r_.append(cc_[j[k]])
        res1 = sum(res1_)
        res2 = sum(res2_)
        res3 = sum(res1_)
        cc_r = sum(cc_r_)
        if res1 >= x and res2 >= x and res3 >= x:
            resList.append(cc_r)
            flag = True

print(min(resList) if flag else -1)

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]"
    A = np.zeros((N,M+1))
    for i in range(N):
        A[i] = [int(next(tokens)) for _ in range(M+1)]
    
    # print(A)
    # print(type(A[0]))
    # 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 numpy as np
import itertools
 
N, M, X = list(map(int, input().split()))
Arr = np.zeros((N,M+1))
List = np.zeros(M)
 
for i in range(N):
    Arr[i] = list(map(int, input().split()))
    
for j in range(M):
    List[j] = np.sum(Arr[:,j])

if np.any(List<10):
    print(-1)

else:
    List = sorted(List)
    for i in range(N+1):
        for team in itertools.combinations(List,i):
            Sum = np.sum(Arr[team,:])
            if np.all(Sum>=10):
                break

Submission status: Runtime Error

Solution code:
import itertools
N, M, X = map(int, input().split())
C = []
A = dict()
for i in range(N):
    CA = list(map(int, input().split()))
    C.append(CA[0])
    for j in range(1, M+1):
        if j in A:
            A[j].append(CA[j])
        else:
            A[j] = [CA[j]]

cost = float("inf")

for i in range(1, N+1):
    for pm in itertools.permutations(list(range(1, N+1)), r=i):
        c = 0
        k = dict()
        for p in pm:
            c += C[p-1]
            if c > cost:
                break

            for m in range(1, M+1):
                if m in k:
                    k[m] += A[m][p - 1]
                else:
                    k[m] = A[m][p - 1]

        if min(k.values()) >= X:
            cost = min(cost, c)


if cost == float("inf"):
    print(-1)
else:
    print(cost)

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)

max_money = 10**5 * N
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 == max_money:
    print(-1)
else:
    print(ans_money)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [False for _ in range(N)]

i = 1
c = 0
jun = []

if K <= N:
    while True:
        K -= 1
        i = A[i-1]
        if K == 0:
            print(i)
            exit()


while True:
    if i == A[i-1]:
        print(i)
        exit()
    if visited[i-1]:
        lp = i
        break
    else:
        visited[i - 1] = True
        jun.append(i)
        i = A[i-1]
        c += 1
ji = jun.index(lp)
K -= len(jun[:ji])
jun = jun[lp:]

kai = K % c

if kai == len(jun) + 1:
    print(jun[0])
else:
    print(jun[kai-1])

Submission status: Runtime Error

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

    if a_all[1]<x or a_all[2]<x or a_all[3]<x:
        return 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-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-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-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-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-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-a
                            judge(a, a_all_)

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

if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

N, M, X = list(map(int, input().split()))
Arr = np.zeros((N,M+1))
List = np.zeros(M)

for i in range(N):
  Arr[i] = list(map(int, input().split()))
  
for j in range(M):
  List[j] = np.sum(Arr[:,j])

if np.any(List<10):
  print(-1)
  
else:
  List = sorted(List)
  for i in range(N+1):
    for team in itertools.combinations(List,i):
      Sum = np.sum(Arr[team,:])
      if np.all(Sum>=10):
        break

Submission status: Runtime Error

Solution code:
N,M,X=map(int,input().split(" "))
A=[[0]*(M+1)]*N
for i in range(0,N):
    A[i]=input().split(" ")
C=[int(x[0]) for x in A ]
Ac=[x[1:] for x in A]
su=0
acd=0
sumup=0
for i in range(0,M):
    temp=[int(x[i]) for x in Ac]
    print(temp)
    for j in range(0,len(temp)):
        su=su+temp[j]
        if su<X:
            can=1
if can==1:
    print("-1")

Submission status: Runtime Error

Solution code:
n,m,x = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
ans = -1
c = []
sum_A = [0] * n
for a in A:
    c.append(a.pop(0))
    for i in range(m):
        sum_A[i] += a[i]
for s in sum_A:
    if s < x:
        print("-1")
    else:
        pass

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[j]
    if np.min(rikai) >= X:
        temp_price = np.sum(C*switch)
        if temp_price < price:
            price = temp_price
    switch = np.zeros(N)
print(int(temp_price))