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:
# -*- coding: utf-8 -*-
import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
#a = cmb(n, r)
#print(a)
'''
def combi(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

def main():

    w=1
    j=0
    k=0
    l=0
    to=[]
    s=0
    #com=[]
    n,m,x=map(int, input().split(" "))
    brray=[list(map(int, input().split(" ")))for i in range(n)]
    #print(brray[2][:])#ちゃんとこれで2行目出力される
    #r=int(input())
    dp= [[0]*(m+1) for i in range(2**n)]#列　行
    #print(dp)
    for i in range(1,m+1):
        to.append(i)
    #print(to)
    for i in range(1,m+1):
        com=list(itertools.combinations(to, i))
        #print(com)
        nn=combi(m,i)
        for j in range(nn):
            #print(len(com[0]))#ちゃんと行けてる
            s +=1
            dlnen=len(com[0])
            #print(dlnen)
            for k in range(dlnen):
                #print('i+j+k',i+j+k,' ',dlnen,com[j][k])
                for l in range(m+1):
                 dp[s][l]=dp[s][l]+brray[com[j][k]-1][l]
    #print(dp)
    #print(dp[2][0])
    ans=100000000000000
    for i in range(2**n):
        if dp[i][0]>0 and dp[i][0]<ans:
            if min(dp[i][1:m]) >=x:
             ans=dp[i][0]
            #for i in range(1,m):
    if ans==100000000000000:
        print(-1)
        sys.exit()
    print(ans)


            #for j in range()
        #print(com[0][0])
        #for j in range(i):

    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    "1行1つの整数を入力を取得し、整数と取得する"
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(number_list)
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)


    #s=input()
    #a=[int(i) for i in s]#int取るとstrでも行ける
    #print(a)
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

a = [[0]*(m+1)]*n
for i in range(n):
	a[i] = list(map(int,input().split()))

r = [0]*m
cost = 0
ok = 0
costtotal = []
for l in range(n):
	for T in itertools.combinations(range(0,n),l):
		for i in range(l):
			cost += a[0][T[i]]
			for j in range(m):
				r[j] += a[j][i+1]
		for j in range(m):
			if r[j] >= x:
				ok += 1
		if ok == m:
			costtotal.append(cost)
		r = [0]*m
		cost = 0
		ok = 0
if costtotal == []:
	print(-1)
else:
	print(min(costtotal))

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
if N == 1:
    CA = list(map(int, input().split()))
    """
    for i in range(1,N):
        if CA[i] < X:
            print(-1)
            break
    """
    print(C)
else:
    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 ** (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())
A=[list(map(int,input().split())) for i in range(N)]
K=np.array([0*M])
m=[]

import numpy as np


def dfs(i, sum,K):
    # n 個決め終わったら、今までの和 sum が k と等しいかを返す
    if i == N:
        for j in K:
            count=0
            while j>=X:
                count+=1
        if count==M
            m.append(sum)
        return count==M
            

    # a[i] を使わない場合
    if dfs(i + 1, sum+K[i][0],K+np.array([for j in A[i][1:]]):
        return True

    # a[i] を使う場合
    if dfs(i + 1, sum,K):
        return True

    # a[i] を使う使わないに拘らず k が作れないので False を返す
    return False
print(min(m) if dfs(0,0,K) else -1)

Submission status: Runtime Error

Solution code:
n,k,x = (int(x) for x in input().split())
C = []
A = []
for i in range(n):
    list = [int(i) for i in input().split()]
    C.append(list[0])
    A.append(list[1:])
case = [0]*(2**n)
chk = []
for i in range(2**n):
    chk.append([0]*m)

for i in range(2 ** n):
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            case[i] += C[j]
            for l in range(m):
                chk[i][l] += A[j][l]

ans = []
flag = [True]*(2**n)
for i in range(2**n):
    for j in range(m):
        if chk[i][j]<x:
            flag[i] = False
    if flag[i]:
        ans.append(case[i])

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

Submission status: Runtime Error

Solution code:
N, M, X = map(int,input().split())
L = []
A = 0
C = []
for i in range(N):
  L.append(list(map(int,input().split())))
for i in range(1,M+2):
  if sum([x[i] for x in L]) < X:
  A += 1
if A > 0:
  print(-1)
else:
  for i in range(2 ** N):
    B = []
    total = 0
    for j in range(N):
      if((i >> j) & 1):
        B.append(L[i])
    D = []
    for k in range(1,M+2):
      if sum([x[i] for x in B]) < X:
        D += 1
    if D = 0:
      C.append(sum([x[0] for x in B]))
  C.sort()
  print(C[0])

Submission status: Runtime Error

Solution code:
def main():
    n,m,x = map(int, input().split())
    c = [list(map(int, input().split())) for _ in range(n)]
    c = sorted(c, key=lambda x:x[0]//sum(x[1:]))
    ans = 0
    rikaido = [0]*m
    possible = False
    for i in c:
        ans += i[0]
        for num, val in enumerate(i[1:]):
            rikaido[num] += val

        if min(rikaido) >= x:
            possible = True
            break
    print(ans) if possible else print(-1)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,k,x = (int(x) for x in input().split())
C = []
A = []
for i in range(n):
    list = [int(i) for i in input().split()]
    C.append(list[0])
    A.append(list[1:])
case = [0]*(2**n)
chk = []
for i in range(2**n):
    chk.append([0]*m)

for i in range(2 ** n):
    for j in range(n):  
        if ((i >> j) & 1):  
            case[i] += C[j]
            for l in range(m):
                chk[i][l] += A[j][l]

ans = []
flag = [True]*(2**n)
for i in range(2**n):
    for j in range(m):
        if chk[i][j]<x:
            flag[i] = False
    if flag[i]:
        ans.append(case[i])

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

Submission status: Runtime Error

Solution code:
import itertools

N, M, X = map(int, input().split())
C = []; A = []; T = []
for _ in range(N):
    s = list(map(int, input().split()))
    T.append(s)


comb = []

for i in range(1,N+1):
    comb.append(list(itertools.combinations(T, i)))

comb = itertools.chain.from_iterable(comb)
count = []

for j in comb:
    t = [0, 0, 0, 0]
    for k in range(len(j)):
        t[0] += j[k][0]
        t[1] += j[k][1]
        t[2] += j[k][2]
        t[3] += j[k][3]
    count.append(t)

count.sort()


for i in count:
    if min(i[1:]) >= X:
        print(i[0])
        exit()

print(-1)

Submission status: Runtime Error

Solution code:
import itertools

n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for i in range(n)]
c=list(itertools.permutations(c))
li=[0]*(n+1)
ans=[]

for i in range(len(c)):
    li=[0]*(n+1)
    for j in range(n):
        t=c[i][j]
        flug=0
        for k in range(m+1):
            li[k]+=t[k]
            if li[k]<x:
                flug=1
        else:
            if flug==0:
                ans.append(li[0])

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

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())))
a.sort()
ans = [0 for i in range(m+1)]
money=1200001

for _ in range(n):
    for i in range(n):
        for j in range(m+1):
            ans[j] += a[i][j]
        if all([t >= x for t in ans[1:]]):
            if ans[0] < money:
                money = ans[0]
    add = a[0]
    a.remove(add)
    a.append(add)
    ans = [0 for i in range(m+1)]

a[0], a[2] = a[2], a[0]
for _ in range(n):
    for i in range(n):
        for j in range(m+1):
            ans[j] += a[i][j]
        if all([t >= x for t in ans[1:]]):
            if ans[0] < money:
                money = ans[0]
    add = a[0]
    a.remove(add)
    a.append(add)    
    ans = [0 for i in range(m+1)]

    
if money != 1200001:
    print(money)
if money == 1200001:
    print(-1)

Submission status: Runtime Error

Solution code:
N,M,X= map(int,input().split())
A=[list(map(int,input().split()) for i in range(N)]
K=np.array([0*M])
m=[]

import numpy as np


def dfs(i, sum,K):
    # n 個決め終わったら、今までの和 sum が k と等しいかを返す
    if i == N:
        for j in K:
            count=0
            while j>=X:
                count+=1
        if count==M
            m.append(sum)
        return count==M
            

    # a[i] を使わない場合
    if dfs(i + 1, sum+K[i][0],K+np.array([for j in A[i][1:]]):
        return True

    # a[i] を使う場合
    if dfs(i + 1, sum,K):
        return True

    # a[i] を使う使わないに拘らず k が作れないので False を返す
    return False
print(min(m) if dfs(0,0,K) else -1)

Submission status: Runtime Error

Solution code:
import numpy as np
n,m,x = map(int,input().split())
all = []
cost = []
result = []
for i in range(n):
    tmp =list(map(int,input().split()))
    all.append(tmp[1:])
    cost.append(tmp[0])
# print(cost)
# print(all)
for i1 in range(m):
    for i2 in range(i1+1,n):
        sum = np.array(all[i1]) +np.array(all[i2])
        flag = True
        for i in sum:
            if(i < x):
                flag = False
        if(flag):
            result.append(cost[i1]+cost[i2])

#3
for i1 in range(n):
    for i2 in range(i1+1,n):
        for i3 in range(i2+1,n):
            sum = np.array(all[i1]) + np.array(all[i2]) + np.array(all[i3]) 
            flag = True
            for i in sum:
                if(i < x):
                    flag = False
            if(flag):
                result.append(cost[i1]+cost[i2]+cost[i3])
#4
for i1 in range(m):
    for i2 in range(i1+1,n):
        for i3 in range(i2+1,n):
                for i4 in range(i3+1,n):
                    sum = np.array(all[i1]) + np.array(all[i2]) + np.array(all[i3])+np.array(all[i4])
                    flag = True
                    for i in sum:
                        if(i < x):
                            flag = False
                    if(flag):
                        result.append(cost[i1]+cost[i2]+cost[i3]+cost[i4])
for i1 in range(m):
    for i2 in range(i1+1,n):
        for i3 in range(i2+1,n):
            for i4 in range(i3+1,n):
                for i5 in range(i4+1,n):
                    sum = np.array(all[i1]) + np.array(all[i2]) + np.array(all[i3])+np.array(all[i4])+np.array(all[i5])
                    flag = True
                    for i in sum:
                        if(i < x):
                            flag = False
                    if(flag):
                        result.append(cost[i1]+cost[i2]+cost[i3]+cost[i4]+cost[i5])
for i1 in range(m):
    for i2 in range(i1+1,n):
        for i3 in range(i2+1,n):
            for i4 in range(i3+1,n):
                for i5 in range(i4+1,n):
                    for i6 in range(i5+1,n):
                        
                        sum = np.array(all[i1]) + np.array(all[i2]) + np.array(all[i3])+np.array(all[i4])+np.array(all[i5])+np.array(all[i6])
                        
                        flag = True
                        for i in sum:
                            if(i < x):
                                flag = False
                        if(flag):
                            result.append(cost[i1]+cost[i2]+cost[i3]+cost[i4]+cost[i5]+cost[i6])
for i1 in range(m):
    for i2 in range(i1+1,n):
        for i3 in range(i2+1,n):
            for i4 in range(i3+1,n):
                for i5 in range(i4+1,n):
                    for i6 in range(i5+1,n):
                        for i7 in range(i6+1,n):
                            sum = np.array(all[i1]) + np.array(all[i2]) + np.array(all[i3])+np.array(all[i4])+np.array(all[i5])+np.array(all[i6])+np.array(all[i7])
                            flag = True
                            for i in sum:
                                if(i < x):
                                    flag = False
                            if(flag):
                                result.append(cost[i1]+cost[i2]+cost[i3]+cost[i4]+cost[i5]+cost[i6]+cost[i7])

for i1 in range(m):
    for i2 in range(i1+1,n):
        for i3 in range(i2+1,n):
            for i4 in range(i3+1,n):
                for i5 in range(i4+1,n):
                    for i6 in range(i5+1,n):
                        for i7 in range(i6+1,n):
                            sum = np.array(all[i1]) + np.array(all[i2]) + np.array(all[i3])+np.array(all[i4])+np.array(all[i5])+np.array(all[i6])+np.array(all[i7])
                            #print(i1,i2,i3,i4,i5,i6,i7,sum)
                            flag = True
                            for i in sum:
                                if(i < x):
                                    flag = False
                            if(flag):
                                result.append(cost[i1]+cost[i2]+cost[i3]+cost[i4]+cost[i5]+cost[i6]+cost[i7])






print(min(result))

Submission status: Runtime Error

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

mincost = 0
for i in range(m):
    mincost += l[i][0]

s = []
for i in range(m):
    s.append(0)

flag = 0

for i in range(2 ** n):
    cost = 0
    for j in range(n):
        if ((i >> j) & 1):
            cost += l[j][0]
            for k in range(1, m):
                s[k] += l[j][k]
    b = 1
    for k in range(1, m):
        if s[k] < x:
            b = 0 
    if b == 1:
        flag = 1
        mincost = min(cost, mincost)
    for i in range(m):
        s[i] = 0

if flag == 1:
    print(mincost)
else:
    print(-1)

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 main(N,M,X,C):
    for i in range(N):
        tmp=[]
        for j in range(N):
            if not i<j:
                continue
            tmp=[C[i][1]+C[j][1],C[i][2]+C[j][2],C[i][3]+C[j][3]]
            if all(map(lambda x:True if x>=X else False,tmp)):
                return C[i][0]+C[j][0]
    return -1

if __name__ == "__main__":
    N,M,X=map(int,input().split())
    C=[list(map(int,input().split())) for c in range(N)]
    print(main(N,M,X,C))

Submission status: Runtime Error

Solution code:
import itertools

N, M, X = map(int, input().split())
C = []; A = []; T = []
for _ in range(N):
    s = list(map(int, input().split()))
    T.append(s)


comb = []

for i in range(1,N):
    comb.append(list(itertools.combinations(T, i)))

comb = itertools.chain.from_iterable(comb)
count = []

for j in comb:
    t = [0, 0, 0, 0]
    for k in range(len(j)):
        t[0] += j[k][0]
        t[1] += j[k][1]
        t[2] += j[k][2]
        t[3] += j[k][3]
    count.append(t)

count.sort()


for i in count:
    if min(i[1:]) >= X:
        print(i[0])
        exit()

print(-1)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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

result = []
adds = []
for j in range(1,n+1):
     for conb in itertools.combinations(san, j):
        result.append(list(conb)) #タプルをリスト型に変換

for i in result:
    t = np.zeros([m+1], dtype=int)
    for j in i:
        t = t + np.array(j)

    adds.append(t)

price = -1
ans = 0
for num, i in enumerate(adds):
    use = True
    for j in range(1,m+1):
        if i[j] < 10:
            # print(i)
            use = False
            break

    if use:
        # print(i)
        # print(result[num])
        if price == -1 or price > i[0]:
        # if price > i[0]:
            price = i[0]
            ans = num

print(price)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

clist=[]
clist2=[]
for i in range(n):
    clist = list(map(int, input().split()))
    clist2.append(clist)

test_list = []

for i in range(1, n+1):
    test = list(itertools.combinations(clist2, i))
    test_list.append(test)

test_list = sum(test_list, [])

def hantei(hant):
    test2 = np.sum(hant, axis=0)
    if all([True if (i >= x) else False for i in test2[1:m+1]]):
        return test2[0]
    else:
        return -1

test3 = list(map(hantei, test_list))

if max(test3) == -1:
    print(-1)
else:
    print(sorted(set(test3))[1])

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import combinations_with_replacement

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

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M):
  if sums[i] < X:
    OK = False
    break
    
if OK == False:
  print(-1)
else:
  min_ = sums[0]
  for A in combinations_with_replacement(range(0, N), r=M):
    A = [*A]
    mini_CA = []
    for i in set(A):
      mini_CA.append(CA[i])
    mini_CA = np.array(mini_CA)
    OK2 = True
    sums = np.sum(mini_CA,axis=0)
    for i in range(1,M):
      if sums[i] < X:
        OK2 = False
        break
    if OK2 == True and sums[0] < min_:
      min_ = sums[0]
      
print(min_)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N, M, X = list(map(int, input().split()))
li = defaultdict(list)





for i in range(N):
    ca = list(map(int, input().split()))
    li[ca[0]] = ca[1:]
li = sorted(li.items())

A = [0]*M
for i in range(len(li)):
    su += int(li[i][0])
    for j in range(M):
        A[j] += int(li[i][1][j])
#print(A)
if any(A[j]<X for j in range(len(A))):
    print('-1')
    exit()
#print(len(li))
#print(su)
ans = su
temp = []
tem = []
for i in range(len(li)-1, -1, -1):
    temp = li[i][1]
    tem = [x-y for (x, y) in zip(A, temp)]
    if all(tem[j]>=X for j in range(len(A))):
        #print('minus:', li[i][0])
        ans -= li[i][0]
        A = tem
        continue
    else:
        continue

print(ans)

Submission status: Runtime Error

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

A = [0]*M
for i in range(N):
    for k in range(M):
        A[k] += CA[i][k+1]
for i in range(M):
    if A[i] < X:
        print('-1')
        exit() 

price = 0
ans = 10**10
A = [0]*M
for i in range(2**N):
    list = [1]*N
    for j in range(len(list)):
        if (i>>j) & 1:
            list[j] = 0
        for k in range(N):
            if list[k] == 1:
                for s in range(M):
                    A[s] += CA[k][s+1]
                price += CA[k][0]
        if all(A[m] >= X for m in range(M)):
            ans = min(ans,price)
    price = 0
print(ans)

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

Submission status: Runtime Error

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

set_list = []
for i in range(2 ** N):
    select = []
    for j in range(N):
        if ((i >> j) & 1):
            select.append(j)
    if len(select) != 0:
        set_list.append(select)
    
cost = []
for i in range(2 ** N - 1):
    cost.append(sum([CA[set_list[i][j]][0] for j in range(len(set_list[i]))]))

skill = []
for i in range(2 ** N - 1):
    tmp = [0]*M
    for j in set_list[i]:
        for k in range(M):
            tmp[k] += CA[j][k+1]
    skill.append(tmp)

pool = []
for i in range(2**N - 1):
    flag = 0
    for j in skill[i]:
        if j < X:
            flag = 1
    if flag == 0:
        pool.append(cost[i])
        

print(min(pool))

Submission status: Runtime Error

Solution code:
from itertools import combinations

N, M, X = map(int, input().split())
skill = [0] * M
N_list = []
C_sum = 0
all_list = [0] * (M+1)

res_list = 0
for i in range(N):
  list_ = list(map(int, input().split()))
  N_list.append(list_)
  all_list = [all_list[i]+list_[i] for i in range(M+1)]
if all(all_list[j] < X for j in range(1, M+1)):
  print(-1)
  exit()
result = []  
for i in range(1, N+1):
  ref = list(combinations(N_list, i))
  for j in range(len(ref)):
    sums = [0] * (M+1)
    for k in range(i):
      sums = [sums[l]+ref[j][k][l] for l in range(M+1)]
    result.append(sums)
kekka = []
for i in range(len(result)):
  if all(result[i][j]>=X for j in range(1, M+1)):
    kekka.append(result[i][0])
print(min(kekka))

Submission status: Runtime Error

Solution code:
def sort(sub_li):
    sub_li.sort(key=lambda x: x[0])
    return sub_li
aa = [x for x in map(int,input().split())]
main = []
d=[]
for i in range(aa[0]):
    t = [x for x in map(int,input().split())]
    d.append(t[0] / t[1])
    main.append(t)
sum = 0
v_d = []
v_sum = 0
z = 0
money = 0
for i in sorted(d):
    v_d.append(i)
total_money = 0
for i in main:
    sum += i[1]
if sum < aa[2]:
    print(-1)
else:
    while v_sum != aa[2]:
        index = d.index(v_d[z])
        money += main[index][0]
        v_sum += main[index][1]
        z+= 1
    print(money)