Problem:


Score : 300 points

Problem

Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0.

Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M).
There is no other way to increase the understanding levels of the algorithms.

Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Constraints

All values in input are integers.

1\leq N, M\leq 12

1\leq X\leq 10^5

1\leq C_i \leq 10^5

0\leq A_{i, j} \leq 10^5

Input

Input is given from Standard Input in the following format:

N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M}

Output

If the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.

Sample Input 1

3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

Sample Output 1

120

Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.

Sample Input 2

3 3 10
100 3 1 4
100 1 5 9
100 2 6 5

Sample Output 2

-1

Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.

Sample Input 3

8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2

Sample Output 3

1067



Sample input:
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9


Sample output:
120

Submission status: Runtime Error

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

a = []

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

ans = []
for i in range(2 ** n):
    b = [0]*n
    price = 0
    for j in range(n):
        if((i >> j) & 1):
            for k in range(m):
                b[k] += a[j][k + 1]
            price += a[j][0]
    if all(l >= x for l in b):
        ans.append(price)

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

Submission status: Runtime Error

Solution code:
import itertools
N,M,X = map(int,input().split())
A = [0,0,0,0]
C = []
Z = []
cz = []
for i in range(N) :
    C.append(list(map(int,input().split())))

for i in range(1,N+1) :
    c = list(itertools.combinations(C,i))
    for j in range(len(c)) :
        A = [0,0,0,0]
        cj = c[j]
        for k in range(i) :
            ck = cj[k]
            A[0]+= ck[0]
            A[1] += ck[1]
            A[2] += ck[2]
            A[3] += ck[3]
        if A[1]>=X and A[2]>= X and A[3]>=X :
            cz.append(A[0])        

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

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
if M == 1:
    if N > 1:
        for i in range(N - 1):
            d = list(map(int, input().split()))
            CA = np.vstack((CA,d))
    C = list(CA[:,0])
    A = list(CA[:,1])
    C_set = []
    for i in range(2 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = 0
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j]
                CC += C[j]
        if S >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))
else:
    if N > 1:
        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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = [0] * M
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j,:]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))

Submission status: Runtime Error

Solution code:
N,M,X = map(int, input().split(' '))
C=[]
maxNum=999999999
dmaxNum=999999999
for i in range(N):
  C.append(map(int, input().split(' ')))

for i in range(2**(N+1)-1):
  ar=[]
  for i in range(M):
    if (i & 2**i) == 0:
      ar = [x * y for (x, y) in zip(ar, C[i])]
  print(ar)
  for i in ar:
    if i < X:
      break

Submission status: Runtime Error

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

import numpy as np
a = np.array(a)


ans =[]
import itertools
k = n
b =0
while k > 1:
    for i in range(1,k):
        l =list(itertools.combinations(range(n),i))
        for j in l:
            b += a[j]
            if (b[1:] > x-1).all():
                ans.append(b[0])
        k -= 1

Submission status: Runtime Error

Solution code:
import itertools
n,m,x = map(int, input().split())
book = []
for i in range(n):
  b = list(map(int, input().split()))
  book.append(b)
book = sorted(book, key=lambda x:x[0])
junretu = itertools.permutations(range(n))
max_ = 2**n
min_nedan = 10**9
for j in range(max_):
  bit = format(j, "0"+str(n)+"b")
  count_list = [0]*m
  nedan = 0
  for b in range(n):
    if bit[b] == "1":
      naiyou = book[b]
      nedan += naiyou[0]
      for i in range(1, m+1):
        count_list[i-1] += naiyou[i]
  if min(count_list)>=x:
    if nedan a< min_nedan:
      min_nedan = nedan
if min_nedan == 10**9:
  print(-1)
else:
  print(min_nedan)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
if M == 1:
    if N > 1:
        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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = 0
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j]
                CC += C[j]
        if S >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))
else:
    if N > 1:
        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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = [0] * M
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j,:]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
if M == 1:
    if N > 1:
        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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = 0
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))
else:
    if N > 1:
        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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = [0] * M
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j,:]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))

Submission status: Runtime Error

Solution code:
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(long, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

n, k = MAP()
a = LIST()
pc = [0] * n

def A(pos, count, loop):
    global a, k, pc

    count += 1
    if k == count:
        print(pos)
    if loop:
        A(a[pos-1], count, True)
    elif pc[pos-1] == 0:
        pc[pos-1] = count
        # print(a[pos-1])
        A(a[pos-1], count, False)
    else:
        k = (k - pc[pos - 1]) % (count - pc[pos - 1])
        # print(str(a[pos-1]) + " : loopStart")
        A(a[pos-1], -1, True)

A(1, 0, False)

Submission status: Runtime Error

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

ans = 10**9
for i in range(2**n):
  cost = 0
  point = [0]*m
  for j in range(n):
    if (i>>j)&1:
      for k in range(1, m+1):
        point[k-1] += books[j][k]
  flag = True
  for j in range(m):n, m, x = map(int, input().split())
books = [0]*n
for i in range(n):
  books[i] = [int(x) for x in input().split()]

ans = 10**9
for i in range(2**n):
  cost = 0
  point = [0]*m
  for j in range(n):
    if (i>>j)&1:
      cost += books[j][0]
      for k in range(1, m+1):
        point[k-1] += books[j][k]
  flag = True
  for j in range(m):
    if point[j] < x:
      flag = False
  if flag and ans > cost:
    ans = cost

print(ans if ans != 10**9 else -1)
    if point[j] < x:
      flag = False
  if flag and ans > cost:
    ans = cost

print(ans if ans != 10**9 else -1)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
if M == 1:
    if N > 1:
        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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = [0]
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))
else:
    if N > 1:
        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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = [0] * M
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j,:]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def can_reach_the_goal(u, x):
    return min(u) >= x

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

c = []
a = []
u = [0]*m
u_sum = [0]*n
for i in range(n):
    ca = [int(row) for row in input().split()]
    c.append(ca[0])
    a.append(ca[1:])
    u_sum[i] += sum(a[i])
    for j in range(m):
        u[j] += a[i][j]

if not can_reach_the_goal(u, x):
    print(-1)
    sys.exit(-1)

idx_c = list(np.argsort(-1 * np.array(c)))
c_sum = sum(c)
for i in idx_c:
    u_tmp = [u[j] - a[i][j] for j in range(m)]
    if can_reach_the_goal(u_tmp, x):
        c_sum -= c[i]
        u = u_tmp

print(c_sum)

Submission status: Runtime Error

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

A = [[] for i in range(N)]
c = [0] * N
for i in range(N):
    c_as = list(map(int, input().split()))
    c[i], A[i] = c_as[0], c_as[1:]

INF = 10**9
ans = INF
for s in range(0, 1 << N):
    smart = [0] * M
    cost_sum = 0
    for i in range(N):
        if (s >> i) % 2 == 0:continue
        cost_sum += c[i]
        for j in range(M):
            smart[j] += A[i][j]
    ok = True
    for i in range(N):
        if smart[i] < X:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def can_reach_the_goal(u, x):
    return min(u) >= x

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

c = []
a = []
u = [0]*m
u_sum = [0]*n
for i in range(n):
    ca = [int(row) for row in input().split()]
    c.append(ca[0])
    a.append(ca[1:])
    u_sum[i] += sum(a[i])
    for j in range(m):
        u[j] += a[i][j]

if not can_reach_the_goal(u, x):
    print(-1)
    sys.exit(-1)

idx_c = list(np.argsort(-1 * np.array(c)))
c_sum = sum(c)
for i in idx_c:
    print(c[i])
    u_tmp = [u[j] - a[i][j] for j in range(m)]
    if can_reach_the_goal(u_tmp, x):
        c_sum -= c[i]
        u = u_tmp

print(c_sum)

Submission status: Runtime Error

Solution code:
N,M,X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()

sums = [0] * M
able = True
for a in A:
    for i in range(M):
        sums[i] += a[i+1]

for s in sums:
    if s < X:
        able = False

if not able:
    print('-1')
    exit()


import itertools

for i in range(1, N+1):
    P = list(itertools.combinations(range(M), i))
    res = float('inf')
    bkFlg = False
    for p in P:
        price = 0
        x = [0]*M
        for j in list(p):
            a = A[j]
            price += a[0]
            for k in range(1, len(a)):
                x[k-1] += a[k]
            flg = True
            for _x in x:
                if _x < X:
                    flg = False
                    break
            if flg:
                res = min(res, price)
                bkFlg = True
                break
    if bkFlg:
        print(res)
        exit()

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 = np.zeros((N,M+1))
    for i in range(N):
        A[i] = [int(next(tokens)) for _ in range(M+1)]
    
    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(np.zeros(M+1), 0)
    
    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

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

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):
  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:
n,m,x=map(int,input().split())
atai=[]
for i in range(0,n):
	atai.append(input().split())

noryoku=0
sassu=12

for j in range(1,m+1):
	for i in range(0,n):
		noryoku=noryoku+int(atai[i][j])
		if noryoku>=x:
			if i+1<=sassu:
				sassu =i+1
				noryoku=0
			else:
				noryoku=0
			break

gokei=0

for k in range(sassu):
	gokei=gokei+int(atai[k][0])

print(gokei)

Submission status: Runtime Error

Solution code:
N,M,X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()

sums = [0] * M
able = True
for a in A:
    for i in range(M):
        sums[i] += a[i+1]

for s in sums:
    if s < X:
        able = False

if not able:
    print('-1')
    exit()


import itertools

for i in range(1, 13):
    P = list(itertools.combinations(range(M), i))
    res = float('inf')
    bkFlg = False
    for p in P:
        price = 0
        x = [0]*M
        for j in list(p):
            a = A[j]
            price += a[0]
            for k in range(1, len(a)):
                x[k-1] += a[k]
            flg = True
            for _x in x:
                if _x < X:
                    flg = False
                    break
            if flg:
                res = min(res, price)
                bkFlg = True
                break
    if bkFlg:
        print(res)
        exit()

Submission status: Runtime Error

Solution code:

import itertools

def main():
    n,m,x = map(int,input().split())
    ans = 0
    tmp = 10 ** 7
    ca = [[0]*m for i in range(n)]
    nn = [i for i in range(n)]

    for _ in range(n):
        ca[_] = list(map(int, input().split()))

    xx = list(itertools.combinations(nn))

    for ii in xx:
        ans = 0
        a = [0 for i in range(m)]

        for _ in ii:
            cost = ca[_][0]
            chk = 0
            for i in range(m):
                a[i] += ca[_][i+1]
                if a[i] < x:
                    chk = 1

            ans += cost
            if chk == 0:
                if tmp > ans:
                    tmp = ans
                break
            
        if tmp == 10 ** 7:
            print(-1)
            exit()

    print(tmp)

 
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
if N > 1:
    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 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = [0] * M
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j,:]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))
else:
    C = CA[0]
    A = CA[1:]
    C_set = []
    for i in range(2 ** (N)):
        book = format(i, '0'+str(N)+'b')
        S = [0] * M
        CC = 0
        for j in range(N):
            if book[j] == "1":
                S = S + A[j,:]
                CC += C[j]
        if min(S) >= X:
            C_set.append(CC)
    if len(C_set) == 0:
        print(-1)
    else:
        print(min(C_set))

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
N,M,X = map(int,input().split( ))
CA = np.array([list(map(int,input().split( ))) for _ in range(N)])
A = CA[:,1:]
C = CA[:,0]
for i in range(N):
    money = []
    xs = []
    for j in itertools.permutations(np.arange(N),i+1):
        x = np.min(np.sum(A[list(j)],0))
        xs.append(x)
        if x >= X:
            money.append(np.sum(C[list(j)]))
    if np.max(xs) >= X:
        ans = np.min(money)
        break
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n,m,x = [int(i) for i in input().split(' ')]

# アルゴリズム理解度
ms = [[] for i in range(n)]
# 各本の金額
en = [0 for i in range(n)]

for i in range(n):
    tmp = [int(i) for i in input().split(' ')]
    en[i] = tmp[0]
    ms[i] = tmp[1:]

X = [int(i) for i in range(m)]
aa = []
for i in range(1,m+1):
    aa += list(itertools.combinations(X,i))

sums = []

for a in aa:
    a = list(a)
    word = [0 for i in range(m)]
    money = [0 for i in range(n)]
    for i in a:
        money[i] += en[i]
        for k, mss in enumerate(ms[i]):
            word[k] += mss
    if min(word) >= x:
        sums += [sum(money)]

if not sums:
    print(-1)
else:
    print(min(sums))

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
if N > 1:
    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 ** (N)):
    book = format(i, '0'+str(N)+'b')
    S = [0] * M
    CC = 0
    for j in range(N):
        if book[j] == "1":
            S = S + A[j,:]
            CC += C[j]
    if min(S) >= X:
        C_set.append(CC)
if len(C_set) == 0:
    print(-1)
else:
    print(min(C_set))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split(" "))
B_list = []


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
# print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    clear = [l for l in bug if l >= X]
    # print(clear)
    bug.pop(0)
    if len(clear) > 1:
        O = clear.pop(0)

    if len(bug) == len(clear):
        ways.append(O)

    bug = []
    for k in range(M + 1):
        bug.append(0)

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

Submission status: Runtime Error

Solution code:
import itertools
N,M,X = map(int,input().split())
A = [0,0,0,0]
C = []
Z = []
cz = []
for i in range(N) :
    C.append(list(map(int,input().split())))

for i in range(2,N+1) :
    c = list(itertools.combinations(C,i))
    for j in range(len(c)) :
        A = [0,0,0,0]
        cj = c[j]
        for k in range(i) :
            ck = cj[k]
            A[0]+= ck[0]
            A[1] += ck[1]
            A[2] += ck[2]
            A[3] += ck[3]
        Z.append(A)

for i in range(len(Z)) :
    zi = Z[i]
    if zi[1]>=X and zi[2]>=X and zi[3]>=X :
        cz.append(zi[0])        

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import sys
import numpy as np
import itertools

cost=0
a = list(map(int,input().split()))
n=a[0]
m=a[1]
x=a[2]
b = [str(input()) for i in range(n)]
calist=[]
for ii in range(n):
    calist.append(list(map(int,b[ii].split())))
temparry=list(itertools.permutations(range(n)))
print(temparry)
flagtmp=False
for ll in range(len(temparry)):
    tempcost=0
    flag=False
    l = [0] * m
    for iii in range(n):
        tempcost=tempcost+calist[temparry[ll][iii]][0]
        for iiii in range(m):
            l[iiii]=l[iiii]+calist[temparry[ll][iii]][iiii+1]
        if(min(l)>=x):
            flag=True
            break
    if(ll==1):
        cost=tempcost
    if(flag):
        flagtmp=Trueue
        if(tempcost<cost):
            cost=tempcost
            
if(cost!=0 and flagtmp):
    print(cost)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

# print(n, m, x, calist)

# check
for j in range(m):
    sum = 0
    for i in range(n):
        sum += calist[i][j + 1]
    if sum < x:
        print(-1)
        exit()

calist = np.array(calist)
dp = float('inf')

for comb in range(1, m + 1):
    sc = itertools.combinations(calist, comb)
    sum = 0
    a = np.array([0 for _ in range(m)])
    for ca in sc:
        sum += ca[0]
        a += ca[1:]
    if False not in (a > x) and sum < dp:
        dp = sum

print(dp)

Submission status: Runtime Error

Solution code:
N, M, X = map(int,input().split())
A=[]
for i in range(N):
    A.append(list(map(int, input().split())))
    
pr=10**9
for s in range(2**N):
    x_m = [0]*13
    for i in range(N):
        b = (s >> i) & 1
        if b == 1:
            pr_s += A[i][0]
            for j in range(M+1):
                x_m[j] += A[i][j]

    xOk = True
    for j in range(1,M+1):
        if x_m[j] < X:
            xOk = False
    
    if xOk == True:
        pr = min(pr, x_m[0])

if pr<10**9:
    print(pr)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split(" "))
B_list = []


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
#print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    clear = [l for l in bug if l >= X]
    #print(clear)
    bug.pop(0)
    O = clear.pop(0)

    if len(bug) == len(clear):
        ways.append(O)

    bug = []
    for k in range(M + 1):
        bug.append(0)

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

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
roop = 0
port = [A[0]]
for _ in range(len(A)):
    port.append(A[port[-1]-1])
    if port.count(A[port[-2]-1]) == 2:#A in port
        port.pop()
        roop = len(port)-port.index(A[port[-1]-1])
        break
K = K-len(port)
print(A[port[K % roop]])

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
lst = list(map(int, input().split()))
data = [-1]*100000

k -= 1
tmp = lst[0]
for i in range(1, k+1):
  #print(tmp, "t")
  if data[lst[tmp-1]-1] >= 1:
    num = (k - data[lst[tmp-1]-1])%(i-data[lst[tmp-1]-1])
    tmp = lst[tmp-1]
    break
  else:
    data[tmp-1] = i
    tmp = lst[tmp-1]


for j in range(num):
  #print(tmp)
  tmp = lst[tmp-1]
print(tmp)

Submission status: Runtime Error

Solution code:
import itertools

n,m,x = map(int,input().split())
ans = 0
tmp = 10 ** 7
ca = [[0]*m for i in range(n)]
nn = [i for i in range(n)]

for _ in range(n):
    ca[_] = list(map(int, input().split()))

xx = list(itertools.combinations(nn))

for ii in xx:
    ans = 0
    a = [0 for i in range(m)]

    for _ in ii:
        cost = ca[_][0]
        chk = 0
        for i in range(m):
            a[i] += ca[_][i+1]
            if a[i] < x:
                chk = 1

        ans += cost
        if chk == 0:
            if tmp > ans:
                tmp = ans
            break
    
    if tmp == 10 ** 7:
        print(-1)
        exit()

print(tmp)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
N,M,X = map(int,input().split( ))
CA = np.array([list(map(int,input().split( ))) for _ in range(N)])
A = CA[:,1:]
C = CA[:,0]
for i in range(N):
    money = []
    xs = []
    for j in itertools.permutations(np.arange(N),i+1):
        x = np.min(np.sum(A[list(j)],0))
        xs.append(x)
        if x >= X:
            money.append(np.sum(C[list(j)]))
    if np.max(xs) >= X:
        ans = np.min(money)
print(ans)

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 = [0 for i in range(m+1)]
    ans_list = []
    for i in text_list:
        a_all = [x + y for(x, y) in zip(a_all, i)]

    if a_all[1]<x or a_all[2]<x or a_all[3]<x:
        return a_all


    def judge(a):
        for i in range(m):
            if a[i]<=x:
                break
        ans_list.append(a)
  
    for i1 in range(n):
        a = text_list[i1]
        a_all_ = [x - y for(x, y) in zip(a_all, a)]
        judge(a)
        judge(a_all_)

    for i1 in range(n-1):
        for i2 in range(i1+1, n):
            a = [a+b for(a, b) in zip(text_list[i1],text_list[i2])]
            a_all_ = [x - y for(x, y) in zip(a_all, a)]
            judge(a)
        	judge(a_all_)
    for i1 in range(n-2):
        for i2 in range(i1+1, n-1):
            for i3 in range(i2+1, n):
                a = [a+b+c for(a, b, c) in zip(text_list[i1],text_list[i2],text_list[i3])]
                a_all_ = [x - y for(x, y) in zip(a_all, a)]
                judge(a)
        		judge(a_all_)

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

    for i1 in range(n-4):
        for i2 in range(i1+1, n-3):
            for i3 in range(i2+1, n-2):
                for i4 in range(i3+1, n-1):
                    for i5 in range(i4+1, n):
                        a = [a+b+c+d+e for(a, b, c, d, e) in zip(text_list[i1],text_list[i2],text_list[i3],text_list[i4],text_list[i5])]
                        a_all_ = [x - y for(x, y) in zip(a_all, a)]
                        judge(a)
        				judge(a_all_)

    for i1 in range(n-5):
        for i2 in range(i1+1, n-4):
            for i3 in range(i2+1, n-3):
                for i4 in range(i3+1, n-2):
                    for i5 in range(i4+1, n-1):
                        for i6 in range(i5+1, n):
                            a = [a+b+c+d+e+f for(a, b, c, d, e, f) in zip(text_list[i1],text_list[i2],text_list[i3],text_list[i4],text_list[i5],text_list[i6])]
                            a_all_ = [x - y for(x, y) in zip(a_all, a)]
                            judge(a)
        					judge(a_all_)

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

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