Problem:


Score : 300 points

Problem

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

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

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

Constraints

All values in input are integers.

1\leq N, M\leq 12

1\leq X\leq 10^5

1\leq C_i \leq 10^5

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

120

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

Sample Input 2

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

Sample Output 2

-1

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

Sample Input 3

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

Sample Output 3

1067



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


Sample output:
120

Submission status: Runtime Error

Solution code:
from itertools import product

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

cost = 10 ** 10
for cand in product((0, 1), repeat=n):
  tmp = 0
  scores = [0] * n
  for bought, ca in zip(cand, CA):
    if not bought:
      continue
    for i in range(1, m + 1):
      scores[i - 1] += ca[i]
    tmp +=  ca[0]
  if min(scores) >= x and tmp < cost:
    cost = tmp
print(cost)

Submission status: Runtime Error

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

ans = 10 ** 7
for i in itertools.product([0, 1], repeat=N):
    tCA = copy.copy(CA)
    for j in range(N):
        if i[j] == 0:
            tCA[j] = np.zeros(CA.shape[1])
    s = np.sum(tCA, axis=0)
    l = sum(k >= X for k in s[1:])
    if s[0] < ans and l == M:
        ans = s[0]

if ans == 10 ** 7:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np
n,m,x = map(int, input().split())
costs = []
understnding = []
ans = 10 ** 20

for _ in range(n):
    tmp = list(map(int, input().split()))
    costs.append(tmp[0])
    understnding.append(tmp[1:])
    
costs = np.array(costs)
understnding = np.array(understnding)

for i in range(2**n):
    row = str(bin(i)).split("0b")[1]
    row = '0'*(n - len(row_tmp))+row_tmp
    one_index = [j for j in range(len(row)) if row[j] =="1"]
    cost_sum = np.sum(costs[one_index])
    under_sum = np.sum(understnding[one_index], axis=0)
    if np.all(under_sum >= x) and cost_sum < ans:
        ans = cost_sum
    
if ans == 10 ** 20:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np
n,m,x = map(int, input().split())
costs = []
understnding = []
ans = 10 ** 20

for _ in range(n):
    tmp = list(map(int, input().split()))
    costs.append(tmp[0])
    understnding.append(tmp[1:])
    
costs = np.array(costs)
understnding = np.array(understnding)

for i in range(2**n):
    row = str(bin(i)).split("0b")[1]
    row = '0'*(n - len(row_tmp))+row_tmp
    one_index = [j for j in range(len(row)) if row[j] =="1"]
    cost_sum = np.sum(costs[one_index])
    under_sum = np.sum(understnding[one_index], axis=0)
    if np.all(under_sum >= x) and cost_sum < ans:
        ans = cost_sum
    
if ans = 10 ** 20:
    print(-1)
else
    print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np
n,m,x = map(int, input().split())
costs = []
understnding = []
ans = 10 ** 20

for _ in range(n):
    tmp = list(map(int, input().split()))
    costs.append(tmp[0])
    understnding.append(tmp[1:])
    
costs = np.array(costs)
understnding = np.array(understnding)
for ele in range(1,m):
    combi = combinations(range(m),ele)
    for j in combi:
        current_under = np.array([sum(understnding[j,ind]) for ind in range(m)])
        tmp_ans = np.sum(costs[list(j)])
        if np.all(current_under>=x) and tmp_ans < ans:
            ans = tmp_ans
if ans != 10 ** 20:
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np
n,m,x = map(int, input().split())
costs = []
understnding = []
ans = 10 ** 20

for _ in range(m):
    tmp = list(map(int, input().split()))
    costs.append(tmp[0])
    understnding.append(tmp[1:])
    
costs = np.array(costs)
understnding = np.array(understnding)
for ele in range(1,m):
    combi = combinations(range(m),ele)
    for j in combi:
        current_under = np.array([sum(understnding[j,ind]) for ind in range(m)])
        tmp_ans = np.sum(costs[list(j)])
        if np.all(current_under>=x) and tmp_ans < ans:
            ans = tmp_ans
if ans != 10 ** 20:
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
#
# abc167 c
#
import sys
from io import StringIO
import unittest
from collections import deque


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3 10
60 2 2 4
70 8 7 9
50 2 3 9"""
        output = """120"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 3 10
100 3 1 4
100 1 5 9
100 2 6 5"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """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"""
        output = """1067"""
        self.assertIO(input, output)


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

    ans = float("inf")
    for bit in range(1 << N):
        S = [0]*(M+1)
        for i, ca in enumerate(CA):
            if (1 << i) & bit == 1 << i:
                S = list(map(sum, zip(S, ca)))
        for s in S[1:]:
            if s < X:
                break
        else:
            ans = min(ans, S[0])

    if ans == float("inf"):
        ans = -1

    print(ans)


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

    b = deque()
    ans = dfs(0, b)
    if ans == float("inf"):
        ans = -1

    print(ans)


def dfs(n, B):
    if n == N:
        S = [0]*(M+1)
        for i, ca in enumerate(CA, 1):
            if i in B:
                S = list(map(sum, zip(S, ca)))
        for s in S[1:]:
            if s < X:
                return float("inf")
        else:
            return S[0]

    ans = float("inf")
    B.append(n+1)
    tmp = dfs(n+1, B)
    ans = min(ans, dfs(n+1, B))
    B.pop()
    ans = min(ans, dfs(n+1, B))

    return ans


if __name__ == "__main__"    ans = min(ans, tmp):
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
def check(understanding,X):
    for individual in understanding:
        if individual<X:
            return False
    return True

cost=0
inputs1 =list(map(int, input().split()[:3]))
N=inputs1[0]
M=inputs1[1]
X=inputs1[2]

matrix=[]
understanding= []
for i in range(N):
    inputs =list(map(int, input().split()[:M+1]))
    matrix.append(inputs)

for i in range(N):
    cost+=matrix[i][0]
    for j in range(1,M+1):
        understanding[j]+=matrix[i][j]
    if check(understanding,X):
        print(cost)
        break

if not check(understanding,X):
    print(-1)

Submission status: Runtime Error

Solution code:
ans = 10**7
for i in range(1<<n):
    mokuhyo = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            for r in range(m):
                mokuhyo[r] += c[j][r+1]
            cost += c[j][0]
    if all(k>=x for k in mokuhyo):
        ans = min(ans, cost)
print("-1" if ans == 10**7 else ans)

Submission status: Runtime Error

Solution code:
ans = float("inf")
for i in range(1<<n):
    mokuhyo = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            for r in range(m):
                mokuhyo[r] += c[j][r+1]
            cost += c[j][0]
    for k in mokuhyo:
        if k < x:
            break
        else:
            ans = min(ans, cost)
print("-1" if ans == 10**7 else ans)

Submission status: Runtime Error

Solution code:
n,m,x = list(map(int, input().split()))
book = []
for i in range(n):
  book.append(list(map(int, input().split())))
ans = 10 ** 5 * n
for i in product([0,1], repeat=n):
  price = 0
  skill = [0] * m
  for index_, bit in enumerate(i):
    if bit:
      for j in range(m):
        skill[j] += book[index_][ j + 1]
        price += book[index_][0]
  if all(v >= x for v in skill):
    ans = min(ans, price)
        
print(ans)

Submission status: Runtime Error

Solution code:
import itertools as it

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

combs = it.product([0, 1], repeat=N)
prices = []
for comb in combs:
    # print(comb)
    bag = [0] * M+1
    for i in range(N):
        if comb[i] == 0:
            continue
        else:
            for j in range(M+1):
                bag[j] += book[i][j]

    if min(bag[1:]) < X:
        continue
    else:
        prices.append(bag[0])

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

Submission status: Runtime Error

Solution code:
import itertools as it

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

combs = it.product([0, 1], repeat=N)
prices = []
for comb in combs:
	bag = [0] * M
	for i in range(N):
		if comb[i] == 0:
			continue
		else:
			for j in range(M):
				bag[j]+=book[i][j]
	if min(bag[1:]) < X:
		continue
	else:
		prices.append(bag[0])

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int n, m, x;
int c[12], a[12][12];

int main()
{
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int all = 1 << n;
    int mincost = INT_MAX;
    for (int mask = 0; mask < all; mask++) {
        int cost = 0;
        vector<int> level(m);
        for (int i = 0; i < n; i++) {
            if ((mask >> i) & 1) {
                cost += c[i];
                for (int j = 0; j < m; j++)
                    level[j] += a[i][j];
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (level[j] < x) ok = false;
        }
        if (ok) {
            mincost = min(mincost, cost);
        }
    }
    if (mincost == INT_MAX)
        cout << -1 << endl;
    else
        cout << mincost << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
C = []
A = []
for _ in range(N):
    l = list(map(int,input().split()))
    C.append(l[0])
    A.append(np.array(l[1:]))
ans = 10**100
for i in range(2**N):
    rikaido = np.zeros(M)
    c = 0
    for j in range(N):
        if (i >> j) & 1:
            c += C[j]
            rikaido += A[j]
    if all([x >= X for x in rikaido]):
        ans = min(ans, c)
print(ans if ans != 10**100 else -1)

Submission status: Runtime Error

Solution code:

def main():
    n, m, x = map(int, input().split(" "))
    ca =[]
    for i in range(n):
        ca.append(list(map(int, input().split(" "))))
    min_c = 1e6
    for i in range(1<<n):
        a = [0]*(m-1)
        c = 0
        for j in range(n):
            if i >> j & 1 ==1:
                for k in range(1,m):
                    a[k-1] += ca[j][k]
                c += ca[j][0]
        if min(a) >= x and c <min_c:
            min_c = c
    if min_c == 1e6: print(-1)
    else:print(min_c)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N,M,X=map(int,input().split())
allList=[]
for _ in range(N):
    allList.append(np.array(list(map(int,input().split()))))
minnum=10**7
for i in range(2**N):
    skill=[0]*(M+1)
    flag=True
    for row in range(N):
        if i&(2**row)>0:
            skill+=allList[row]
    for i in range(M):
        if skill[j+1]<X:
            flag=False
    if flag:
        minnum=min(minnum,skill[0])
if minnum==10**7:
    minnum=-1
print(minnum)

Submission status: Runtime Error

Solution code:
from operator import sub, add
import sys
N, M, X = map(int, input().split())
AC = []
for _ in range(N):
    AC.append(list(map(int, input().split())))

S = [sum(x) for x in zip(*AC)]
s = [sum(x) for x in zip(*AC)]
for m in range(1, M+1):
    if s[m] < X:
        print(-1)
        sys.exit(0)
        
AC.sort(reverse=True)        
for n in range(N):
    ac = AC[n]
    s = list(map(sub, s, ac))
    for m in range(1, M+1):
        if s[m] < X:
            s = list(map(add, s, ac))
            break
            
print(min(S, s[0]))

Submission status: Runtime Error

Solution code:
import itertools as it
N, M, X = map(int,input().split())
book = [[int(_) for _ in input().split()] for i in range(N)]

combs = it.product([0,1], repeat=N)
prices = []
for comb in combs:
    # print(comb)
    bag = [0]*M
    for i in range(N):
        if comb[i] == 0:
            continue
        else:
            for j in range(M):
                bag[j] += book[i][j]
    
    if min(bag[1:]) < X:
        continue
    else:
        prices.append(bag[0])

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

Submission status: Runtime Error

Solution code:
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
from itertools import combinations
s=list(range(n))
ans=10**10
array=[0]*n
res=0
for ii in range(1,n+1):
    for i in combinations(s,ii):
        for j in i:
            res+=ca[j][0]
            for k,l in enumerate(ca[j][1:]):
                array[k]+=l
        if min (array)>=x:
            ans=min(ans,res)
        res=0
        array=[0]*m

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

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
C = [(list(map(int, input().split()))) for _ in range(N)]
 
# bit全探索を行い、参考書に関する全ての組みについて、値段と理解度を求める
ans = 10**10
for i in range(2**N):
  U = [0]*(M+1)
  for j in range(N):
    if ((i >> j) & 1):
      for k in range(M+1):
        U[k] += C[j][k]
  
  # ある組みが条件を満たすなら、その値段をvalに追加
  if sum([u >= X for u in U[1:]]) == M:
    ans = min(ans, U[0])

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

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
C = [(list(map(int, input().split()))) for _ in range(N)]
 
# bit全探索を行い、参考書に関する全ての組みについて、値段と理解度を求める
ans = 10**10
for i in range(2**N):
  U = [0]*(M+1)
  for j in range(N):
    if ((i >> j) & 1):
      for k in range(M+1):
        U[k] += C[j][k]
  
  # ある組みが条件を満たすなら、その値段をvalに追加
  if sum([u >= X for u in U[1:]]) == M:
    ans = min(ans, M[0])

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

Submission status: Runtime Error

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

#print(n, m, x, a)

#0b00・・・０~0b111・・・１を全部作成
cost_abl = []
cost_lis = []
abl_lis = []
for i in range(1 << n):
    cost = 0
    abl_sum = [0] * (len(a))
    #print(abl_sum)
    #abl_1, abl_2, abl_3 = 0, 0 ,0
    for j in range (len(a)):
        mask = 1 << j
        if i & mask:
            cost += a[j][0]
            for k in range(len(a)):
                abl_sum[k] += a[j][k + 1]
            # abl_1 +=  a[j][1]
            # abl_2 += a[j][2]
            # abl_3 += a[j][3]
    cost_lis.append(cost)
    abl_lis.append(abl_sum)
    #print(bin(i))
#print(cost_lis, abl_lis)

cost_new_lis = []
for i in range(len(abl_lis)):
    if min(abl_lis[i]) >= x:
        cost_new_lis.append(cost_lis[i])
    else:
        pass
#print(cost_new_lis)

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

Submission status: Runtime Error

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

min_sum_answer = 0
for i in range(n**2):
      min_sum = 0
      get_score = []
      for m in range(m):
         get_score.append(0)   
      for j in range(n):
            if i >> j % 2 ==1:
                  mun_sum += c_a[j][0]
                  for l in range(m):
                        get_score[l] += c_a[j][l+1]
           
      pre = 0 
      for s in range(m):
            if(get_score[s} < x):
                  pre = 1
                  break
      
      if pre == 0:
            if min_sum_answer == 0:
                  min_sum_answer = min_sum 
            elif min_sum_answer > min_sum:
                  min_sum_answer = min_sum 

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

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split(' '))
price, exp, rst = [], [ [] for i in range(M)], -1
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp[i] = ls[1:]
for i in range(1 << N):
    price_combi, exp_combi, exp_sum, cnt_ls = [], [], [0] * M, []
    for j in range(N):
        if i >> j & 1:
            price_combi.append(price[j])
            exp_combi.append(exp[j])
    for s in exp_combi:
        for t in range(M):
            exp_sum[t] += s[t]
    [ cnt_ls.append(x) for x in exp_sum if x >= X ]
    if len(cnt_ls) == M:
        if rst == -1:
            rst = sum(price_combi)
        else:
            rst = min(rst, sum(price_combi))
print(rst)

Submission status: Runtime Error

Solution code:
import itertools

def abc167c_skill_up():
    n, m, x = map(int, input().split())
    c = []
    a = []
    for _ in range(n):
        v = list(map(int, input().split()))
        c.append(v[0])
        a.append(v[1:])
    pattern = itertools.product([0,1], repeat=n)
    best = float('inf')
    for p in pattern:
        cost = 0
        skill = [0] * n
        for i, v in enumerate(p):
            if v == 1:
                cost += c[i]
                if cost > best: break
                check = True
                for j in range(m):
                    skill[j] += a[i][j]
                    if skill[j] < x:
                        check = False
                if check:
                    best = cost
                    break
    if best == float('inf'):
        print('-1')
    else:
        print(best)
abc167c_skill_up()

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split(' '))
price, exp, rst = [], [ [] for i in range(N) ], -1
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp[i] = ls[1:]
for i in range(1 << M):
    price_combi, exp_combi, exp_sum, cnt_ls = [], [], [0] * M, []
    for j in range(M):
        if i >> j & 1:
            price_combi.append(price[j])
            exp_combi.append(exp[j])
    for s in exp_combi:
        for t in range(M):
            exp_sum[t] += s[t]
    [ cnt_ls.append(x) for x in exp_sum if x >= X ]
    if len(cnt_ls) == M:
        if rst == -1:
            rst = sum(price_combi)
        else:
            rst = min(rst, sum(price_combi))
print(rst)

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * (M+1)
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if M==1 and min(g[1]) < X:
        continue
    elif M>1 and min(g[1:M]) < X:
        continue
    else:
        cnt.append(g[0])
if len(cnt) ==0:
    print(-1)
else:
    print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * (M+1)
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if min(g[1:M]) < X:
        continue
    else:
        cnt.append(g[0])
if len(cnt) ==0:
    print(-1)
else:
    print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * (M+1)
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
            x = g[1:M]
    if min(x) < X:
        continue
    else:
        cnt.append(g[0])
if len(cnt) ==0:
    print(-1)
else:
    print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * (M+1)
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if g[1:M] < X:
        continue
    else:
        cnt.append(g[0])
if len(cnt) ==0:
    print(-1)
else:
    print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * (M+1)
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if g[1]<X or g[2]<X or g[3]<X:
        continue
    else:
        cnt.append(g[0])
if len(cnt) ==0:
    print(-1)
else:
    print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * (M+1)
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if g[1]<X or g[2]<X or g[3]<X:
        continue
    else:
        cnt.append(g[0])
print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * M+1
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if g[1]<X or g[2]<X or g[3]<X:
        continue
    else:
        cnt.append(g[0])
print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0]*M
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if g[1]<X or g[2]<X or g[3]<X:
        continue
    else:
        cnt.append(g[0])
print(min(cnt))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0]*4
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if g[1]<X or g[2]<X or g[3]<X:
        continue
    else:
        cnt.append(g[0])
print(min(cnt))

Submission status: Runtime Error

Solution code:
    import copy
    N,M,X = (int(x) for x in input().split())
    CA = [[0] * (M+1) for k in range(N)]
    SUM_A = [0]*(M)
    SUM_C = 0
    
    for i in range(N):
      ca = list(map(int, input().split()))
      SUM_C += ca[0]
      for j in range(M+1):
        CA[i][j] = ca[j]
        if j>0:
          SUM_A[j-1] += ca[j] 
    
    CA = sorted(CA, reverse=True)
    #print(CA)
    #print(SUM_C,SUM_A)

    c = True

    for l in range(M):
      SUM_A[l] -= X
      if SUM_A[l] < 0:
        c = False
    if c == False:
      print(-1)
    else:
      for m in range(N):
        sum_a = copy.copy(SUM_A)
        for n in range(M):
          sum_a[n] -= CA[m][n+1]
          if sum_a[n] < 0:
            break
          else:
            SUM_A[n] = sum_a[n]
            if n == M-1:
              SUM_C -= CA[m][0]
      print(SUM_C)

Submission status: Runtime Error

Solution code:
import math
N,M,X = map(int,input().split())
#a[i][0]:price of the i-th book
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int,input().split()))
a.sort()
#dp[j][k]:lowest amount of money needed to make j-th algorithm level k
dp = [[math.inf for k in range(X+1)] for j in range(M)]

for j in range(M):
    dp[j][0] = 0

for i in range(N):
    for j in range(M):
        for k in range(X,a[i][j+1],-1):
            dp[j][k] = min(dp[j][k],dp[j][k-a[i][j+1]] + a[i][0])
        for k in range(1,a[i][j+1]+1):
            dp[j][k] = min(dp[j][k],a[i][0])

#print(dp)
maximum = 0
for j in range(M):
    maximum = max(maximum,dp[j][X])
if maximum == math.inf:
    print(-1)
else:
    print(maximum)

Submission status: Runtime Error

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

# 購買する全パターンを回す
most_row_price = 10**10
for i in range(2**n):
    comb = str(bin(i)[2:]).zfill(n)
    
    # 購買パターン毎の購入金額と理解度を算出する
    money_per_pattern = [0] * n # 購買パターン毎の金額の初期化
    total_money = 0 # 合計購入金額の初期化
    for j in range(n):
        
        # 購入しないケースは除外する
        if comb[j] == '0':
            continue
            
        # 購入するケースだけ、金額算出する
        total_money += ca[j][0]
        
        # 当該パターンの理解度を算出する
        for k in range(m):
            understanding[k] += ca[j][k+1]           

    for j in range(m):
        if understanding[j] < x:
            break
    else:
        most_row_price = min(total_money, most_row_price)

if most_row_price == 10**10:
    print(-1)
else:
    print(most_row_price)

Submission status: Runtime Error

Solution code:
import itertools


def main():
    n, m, x = map(int, input().split())
    lst = []
    for _ in range(n):
        lst.append(list(map(int, input().split())))

    flag1 = True
    max_lst = []
    for i in range(m):
        understanding = 0
        for j in range(n):
            understanding += lst[j][i+1]
        max_lst.append(understanding)

    for i in range(len(max_lst)):
        maximum = max_lst[i]
        if maximum < x:
            cost = -1
            flag1 = False
            break

    if flag1:
        number = 1
        cost_lst = []
        while number <= m:   ##一冊laからどんどん増やす
            n_lst = []
            for i in range(n):
                n_lst.append(i)
            choice = list(itertools.combinations(n_lst, number))
            combination_number = len(choice)
            choice_number = len(choice[0])

            for i in range(combination_number):

                cost1 = 0
                understanding_lst = [0] * m
                for j in range(choice_number):  ##一組終了
                    choiced_number = choice[i][j]
                    cost1 += lst[choiced_number][0]

                    for k in range(1, m + 1):
                        unstg = lst[choiced_number][k]
                        understanding_lst[k - 1] += unstg

                over_x = 0
                for l in range(m):
                    understanding = understanding_lst[l]
                    if understanding >= x:
                        over_x += 1

                if over_x == m:
                    cost_lst.append(cost1)

            number += 1

        cost = min(cost_lst)

    print(cost)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
n,m,x=map(int,input().split())
a=0
b=[[np.array(list(map(int,input().split())))]for i in range(n)]
for i in range(2**n):
    c=bin(i)
    c="0"*(n-len(c))+c
    l=np.zeros(m)
    q=0
    for j in range(n):
        if c[j]=="1":
            q+=b[j][0]
            l+=b[j]
    if np.min(l)==x:
        a=min(a,q)
if a:
    print(a)

Submission status: Runtime Error

Solution code:
import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
    x = list(map(int, input().split()))
    C[i] = x[0]
    A[i] = [0] * M
    for j in range(M):
        A[i][j] = x[j + 1]
cnt = [0] * (2 **N)
ans_list = []
for i in range(2 ** N):
    bag = []
    cnt[i] = [0] * M
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(C[j])  # フラグが立っていたら bag に果物を詰める
            for k in range(M):
                cnt[i][k] += A[j][k]
    if bisect.bisect_left(cnt[i], X) == 0:
        ans_list.append(sum(bag))
if ans_list == []:
    print(-1)
else:
    print(min(ans_list)

Submission status: Runtime Error

Solution code:
import copy

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

res = 10**8

C = [0] * N
A = [0] * N

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

def sum_l(a,b):
    for i in range(len(a)):
        a[i] += b[i]
    return a

def check_x(a):
    for i in range(len(a)):
        if a[i] < X:
            return False
    return True

# n…2^12(12bit)の整数
def calc_money_under(n):
    understand = [0] * M
    money = 0
    for s in range(N):
        if (n >> s) == 1:
            money += C[s]
            #tmp = copy.copy(understand)
            understand = copy.copy([x + y for (x,y) in zip(understand, A[s])])
            print(understand)
    
    if check_x(understand):
        res = min(sum(money), res)
    return

for n in range(2**N):
    calc_money_under(n)

if res == 10**8:
    print(-1)
else:
    print(res)