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 fractions import gcd
from functools import reduce
# from collections import deque
# from math import factorial
import collections
import math
import sys
sys.setrecursionlimit(2000000)
n, m, x = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
#n = int(input())
# n, m = list(map(int, input().split()))
a = []
for i in range(n):
    b = list(map(int, input().split()))
    t = sum(b)-b[0]
    #print(t)
    b.append(b[0]/t)
    a.append(b)

a_sorted = sorted(a, key=lambda x: x[-1])

money = 0
point = [0]*m
for i in range(n):
    fin = True
    money += a_sorted[i][0]
    for j in range(m):
        #print(money)
        point[j] += a_sorted[i][j+1]
        # print(a_sorted[i][0])
    #print(point, end=" ")
    #print(money)
    for j in range(m):
        if point[j] < x:
            fin = False
    if fin:
        print(money)
        exit()

    # print(check)
print(-1)

Submission status: Runtime Error

Solution code:
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))

def case():
    n,k=li()
    a=li()
    d=defaultdict(int)
    i=0
    d[1]=1
    c=0
    ans=[1]
    while(a[i] not in d):
        d[a[i]]=1
        c+=1 
        ans.append(a[i])
        i=a[i]-1
   # print(i)
    #print(ans)
    if(k<len(ans)):
        print(ans[k%len(ans)])
        return
    for j in range(len(ans)):
        if(ans[j]==a[i]):
            ans=ans[j:]
            k-=j
            break 

    #print(ans,k)
    print(ans[(k)%len(ans)])
    




for _ in range(1):
    case()

Submission status: Runtime Error

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

CAM = list([list(map(int,input().split())) for i in range(N)])
# print(CAM)
minn = 10**6
b = False

for i in range(2 ** N):
    bag = []
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(CAM[j])  # フラグが立っていたら bag に果物を詰める

    s = 0
    x=0
    y=0
    z=0
    for ij in range(len(bag)):
      s += bag[ij][0]
      x += bag[ij][1]
      y += bag[ij][2]
      z += bag[ij][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:
# -*- coding: utf-8 -*-
n, m, x = map(int, input().split())
L = []
J = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)
for i in range(2**n):
    cost = 0
    f = 0
    M = [0]*m
    for j in range(n):
        
        if (i>>j)&1 == 1:
            cost += L[j][0]
            for k in range(m):
                M[k] += L[j][k+1]
    for p in M:
        if p < x:
            f = 1
    if f == 0:
        J.append(cost)
print(min(J))

Submission status: Runtime Error

Solution code:
import copy
from collections import Counter

import numpy as np

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

cc = np.sum(CA[:, 0])
U = 10**5 * cc +1

dp = np.full([M, 10**5 * M + 1], U, dtype=np.int32)
dp[:, 0] = 0

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

    for i, v in enumerate(a):
        p_dp = copy.deepcopy(dp)
        np.minimum(dp[i, v:], p_dp[i, :-v] + c, out=dp[i, v:])

p_ans = dp[:, X:]

ans_list = []
for i in range(M):
    ans_list += list(set(p_ans[i]))

C = sorted(Counter(ans_list).items())

for k, v in C:
    if v >= M:
        if k >= U:
            print(-1)
            break
        else:
            print(k)
            break
else:
    print(-1)

Submission status: Runtime Error

Solution code:
#C
import numpy as np
flg = True
n,m,x = map(int,input().split())
algo = []
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
    for i in range(len(lst1)):
        l1 = lst1[i]
        l2 = lst2[i]
        l1 -= l2
        lst1[i] = l1
            
    return lst1

if flg:
    for i in range(n):
    flg = True
    for j in range(1,m+1):
        if gokei[j-1] - algo[i][j] < x:
            flg = False
            pass
    if flg:
        gokei = hikizan(gokei,algo[i][1:])
        money -= algo[i][0]
        
print(money)

Submission status: Runtime Error

Solution code:
n,m,x = map(int,input().split())
a = [0]*n
for i in range(n):
    a[i] = list(map(int,input().split()))
    
import itertools
data = list(range(n))
r = n
cc = list(itertools.permutations(data, r))

count = 0
ans = 10**7
for s in cc:
    count = 0
    sw = [0]*n
    for j in range(len(s)):
        
        for i in range(m):
            sw[i] += a[s[j]][i+1]
        count += a[s[j]][0]
        q = 1
        for k in range(m):
            if sw[k] < x:
                q = 0
                break
        if q == 1:
            ans = min(ans,count)
if ans == 10**7:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

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

CAM = list([list(map(int,input().split())) for i in range(N)])
# print(CAM)
minn = 10**9
b = False
for i in range(2 ** N):
    bag = []
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(CAM[j])  # フラグが立っていたら bag に果物を詰める

    s = 0
    x=0
    y=0
    z=0
    for i in range(len(bag)):
      s += bag[i][0]
      x += bag[i][1]
      y += bag[i][2]
      z += bag[i][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:
A, B, C, K = map(int, input().split())

if A > K:
    print(K)
elif A+B >= K:
    print(A)
else:
    print(A - (K-(A+B)))

Submission status: Runtime Error

Solution code:
import itertools
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
sum=[0]*m
for i in range(n):
  for j in range(1,m+2):
    sum[j]+=l[i][j]
for ss in sum:
  if ss<x:
    print(-1)
    exit()
list=[]
for p in itertools.product([1,0],n)
  cnt=[0]*m
  ans=0
  for i in range(n):
    if p[i]==1:
      ans+=l[i][0]
      list.append(ans)
      for j in range(1,m+1)
        cnt[j]+=l[i][j]
print(min(list))

Submission status: Runtime Error

Solution code:
#n = int(input())
n,m,x = map(int,input().split())
#a_L = list(map(int,input().split()))
import itertools
L = list(itertools.permutations(list(range(0,n))))
#print(L)
a_L = []
c_L = []

import numpy as np

def check_L(L,x):
    flag = True
    for i in range(len(L)):
        if L[i] < x:
            flag = False
    return flag
        

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

ans_price = float("inf")
copy_L = np.array([0 for i in range(m)])

for z in L:
    ans_L = copy.deepcopy(copy_L)
    
    price = 0
    for i in z:
        price += c_L[i]
        ans_L += a_L[i]
        if check_L(ans_L,x):
            ans_price = min(ans_price,price)
            break
if ans_price == float("inf"):
    print(-1)
else:
    print(ans_price)

Submission status: Runtime Error

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

import numpy as np

vals = []
for i in range(N):
    v = list(map(int, input().split(" ")))
    vals.append(v)

vals = np.array(vals)

import itertools

prod = []
for i in range(1, N+1):
    v = list(itertools.combinations(range(N), i))
    prod.extend(v)
    
money = 1e8

for p in prod:
    ans = np.zeros(4)
    for p_ in p:
        ans += vals[p_]
    if (ans[1] >= X) and (ans[2] >= X) and (ans[3] >= X):
        if money > ans[0]:
            money = ans[0]
 
if money >= 1e8:
    print(-1)
else:
    print(int(money))

Submission status: Runtime Error

Solution code:
A,B,C,K=(int(x) for x in input().split())

if(K<=A+B):
    print(A)
if(K>A+B):
    print(A-(K-A-B))

Submission status: Runtime Error

Solution code:
n,m,x = map(int,input().split())
c_list = [list(map(int,input().split())) 
          for nesya in range(n)]
arugo = [0]*m
hoge = 0
for c in c_list:
  arugo[0] += c[1]
  arugo[1] += c[2]
  arugo[2] += c[3]
  hoge += c[0]
if arugo[0] < 10 or arugo[1] < 10 or arugo[2] < 10:
  print(-1)
else:
  print(hoge)

Submission status: Runtime Error

Solution code:
n,m,x = map(int,input().split())
c_list = [list(map(int,input().split())) 
          for nesya in range(n)]
arugo = [0]*m
hoge = 0
while c in c_list:
  arugo[0] += c[1]
  arugo[1] += c[2]
  arugo[2] += c[3]
  hoge += c[0]
if arugo[0] < 10 or arugo[1] < 10 or arugo[2] < 10:
  print(-1)
else:
  print(hoge)

Submission status: Runtime Error

Solution code:
N,M,X=[int(x) for x in input().rstrip().split()]
l=[]
for i in range(N):
  ca=[int(x) for x in input().rstrip().split()]
  l.append(ca)

A=[0 for i in range(M+2)]
flag=1
ans=10**10
cnt=0
for i in range(2**N):
  flag=1
  cost=0
  for j in range(N):
    if i>>j & 1:
      now=l[N-j-1]
      cost+=now[0]
      for s in range(M):
        A[s]+=now[s+1]
  for t in range(M):
    if X<=A[t]:
      continue
    else:
      flag=0
      break
  if flag==1:
    ans=min(ans,cost)
    cnt+=1

  A=[0 for v in range(N)]

if cnt==0:
  print(-1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
N,M,X=[int(x) for x in input().rstrip().split()]
l=[]
for i in range(N):
  ca=[int(x) for x in input().rstrip().split()]
  l.append(ca)

A=[0 for i in range(M+2)]
flag=1
ans=float('inf')
cnt=0
for i in range(2**N):
  flag=1
  cost=0
  for j in range(N):
    if i>>j & 1:
      now=l[N-j-1]
      cost+=now[0]
      for s in range(M):
        A[s]+=now[s+1]
  for t in range(M):
    if X<=A[t]:
      continue
    else:
      flag=0
      break
  if flag==1:
    ans=min(ans,cost)
    cnt+=1

  A=[0 for v in range(N)]

if cnt==0:
  print(-1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(m)
    mm = 0
    for j in range(len(s)):
        if s[j] == '1':
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)

Submission status: Runtime Error

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

def tas(l1,l2):
    l3=[]
    for i in range(m+1):
        l3.append(l1[i]+l2[i])
    return l3


ll=[[0 for i in range(m+1)]]
for i in range(n):
    for j in range(len(ll)):
        ll.append(tas(ll[j],l[i]))

lm=[]
for i in ll:
    lll=[]
    for j in range(1,i):
        if i[j]>=x:
            lll.append(True)
        else:
            lll.append(False)
    if all(lll)==True:
        lm.append(i[0])

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

Submission status: Runtime Error

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

data = []

tcost,ca,cb,cc = 0,0,0,0

for i in range(n):
	inp = list(map(int,input().split()))
	ca += inp[1]
	cb += inp[2]
	cc += inp[3]
	data.append(inp)
	tcost += inp[0]


if (ca < x or cb < x or cc < x):
	print(-1)
	exit(0)


data = sorted(data, key= lambda x:x[0], reverse=True)


for i in range(len(data)):
	nca = ca - data[i][1]
	ncb = cb - data[i][2]
	ncc = cc - data[i][3]
	
	if (nca >= x and ncb >= x and ncc >= x):
		tcost -= data[i][0]
		ca -= data[i][1]
		cb -= data[i][2]
		cc -= data[i][3]
	
	
print(tcost)

Submission status: Runtime Error

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


C =[]
A = {}

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

bestscore = 99999999999
def rec(n, score, money):
    global bestscore
    if n==N: return
    s = copy.deepcopy(score)
    rec(n+1, s, money)

    money += C[n]
    for i in range(M):
        score[i] += A[n][i]
    

    for i in range(M):
        if score[i] < X:
            s = copy.deepcopy(score)
            rec(n+1, s, money)
            return
    bestscore = min(bestscore, money)

score = [0 for i in range(N)]

rec(0, score, 0)
if bestscore == 99999999999:
    print(-1)
else:
    print(bestscore)

Submission status: Runtime Error

Solution code:
import numpy as np

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

values = []
scores = []
greedy = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    values.append(tmp[0])
    scores.append(tmp[1:])
    greedy.append(np.sum(scores)/tmp[0])

values = np.array(values)
scores = np.array(scores)

selected = []
finished = []
finisheds = np.zeros(M)
ans = 0
while len(finished) != M and np.sum(greedy)!=0:
    arg = np.argmax(greedy)
    selected.append(arg)
    finisheds += scores[arg]
    ans += values[arg]
    scores[selected] = 0
    args = np.where(finisheds>=X)[0]
    finished.extend(list(args))
    finished = list(set(finished))
    for arg in args:
        scores[:, arg] = 0
    greedy = np.sum(scores, axis=1)/values
    for arg in finished:
        greedy[arg] = 0

if len(finished) == M:
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
N,M,X=[int(x) for x in input().rstrip().split()]
l=[]
for i in range(N):
  ca=[int(x) for x in input().rstrip().split()]
  l.append(ca)

A=[0]*(M+2)
flag=1
ans=float('inf')
cnt=0
for i in range(2**N):
  flag=1
  cost=0
  for j in range(N):
    if i>>j & 1:
      now=l[N-j-1]
      cost+=now[0]
      for s in range(M):
        A[s]+=now[s+1]
  for t in range(M):
    if X<=A[t]:
      continue
    else:
      flag=0
      break
  if flag==1:
    ans=min(ans,cost)
    cnt+=1

  A=[0]*N

if cnt==0:
  print(-1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
n,m,x = map(int,input().split())
A = [[] for _ in range(n)]
for i in range(n):
    A[i] = list( map(int,input().split()) )
    
flag = 0
min_charge = 10**7

for i in range(2**n):
    which = format(i, '#010b')[-n:]
    
    #print(which,end = ':')
    
    charge = 0
    skill = [0 for _ in range(m)]
    for j in range(n):
        if which[j]=='1':
            charge += A[j][0]
            for k in range(m):
                skill[k]+=A[j][k+1]
    flag_skill = 1
    for l in range(m):
        if skill[l] < x:
            flag_skill = 0
    
    
    #print(skill,end=':')
    #print(charge,end=':')    
    
    if flag_skill ==1:
        min_charge = min(min_charge,charge)
    
    #print(flag_skill)

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

Submission status: Runtime Error

Solution code:
a=input().split()
N=int(a[0])
M=int(a[1])
X=int(a[2])
list1=[]
for i in range(N) :
  k=input().split()
  k=[int(j) for j in k]
  list1.append(k)
flag1=True
def count(item,i) :
  count=0
  for a in item :
    count+=a[i]
  return count

import itertools
for i in range(1,N+1) :
  c=list(itertools.combinations(list1,i))

  value_list=[]
  for item in c :
    item1=list(item)


    if count(item,1)>=X and count(item,2)>=X and count(item,3)>=X :
      value_list.append(count(item,0))
  if value_list!=[] :
    print(min(value_list))
    flag1=False

    break
if flag1 :
  print('-1')

Submission status: Runtime Error

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

# print(A)
# print(C)

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

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

Submission status: Runtime Error

Solution code:
a=input().split()
N=int(a[0])
M=int(a[1])
X=int(a[2])
list1=[]
for i in range(N) :
  k=input().split()
  k=[int(j) for j in k]
  list1.append(k)
flag1=True
def count(item,i) :
  count=0
  for a in item :
    count+=a[i]
  return count

import itertools
import numpy as np
for i in range(1,N+1) :
  c=list(itertools.combinations(list1,i))

  value_list=[]
  for item in c :
    item1=list(item)


    if count(item,1)>=X and count(item,2)>=X and count(item,3)>=X :
      value_list.append(count(item,0))
  if value_list!=[] :
    print(min(value_list))
    flag1=False

    break
if flag1 :
  print('-1')

Submission status: Runtime Error

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

import  itertools
import numpy as np

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

#print(A)
l = [1, 0]
ll = list(itertools.product(l, repeat=N))
#print(ll)
ans = float("inf")
for i in ll:
    jdg = np.array([0] * (M+1))
    for k in range(N):
        if i[k] == 1:
             jdg = jdg + A[k]
    #print(jdg)
    if min(jdg[1:]) >= X:
        ans = min(ans,jdg[0])
    #print(min(jdg[1:]))
if ans != float("inf"):
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
b0=input().split()
book=int(b0[0])
pro=int(b0[1])
norma=int(b0[2])

bl=[]
for x in range(book):
  bl.append([int(y) for y in input().split()])
  
def find(n,exl):
  if n==book:
    if min(exl)<norma:
      return -1
    else:
      return 0
  else:
    if min(exl)>=norma:
      return 0
    else:
      newexl=[]
      for i in range(pro):
        newexl.append(exl[i]+bl[n][i+1])
      if min(newexl)>=norma:
        f0=bl[n][0]
      else:
        re=find(n+1,newexl)
        if re==-1:
          f0=-1
        else:
          f0=re+bl[n][0]
      re2=find(n+1,exl)
      if re2==-1:
        f1=-1
      else:
        f1=re2
      if f0==-1 and f1==-1:
        return -1
      elif f0==-1 or f1==-1:
        return max(f0,f1)
      else:
        return min(f0,f1)
      
print(find(0,[0 for i in range(book)]))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, X = map(int, input().split())
prices = []
effects = []
for i in range(N):
    c, *a = map(int, input().split())
    prices.append(c)
    effects.append(list(a))

prices = np.array(prices)
effects = np.array(effects)


ans = float("inf")

pats = []
for i in range(2 ** N):
    pat = bin(i).replace("0b", "")
    pat += "0" * (N - len(pat))
    pat = list(map(int, list(pat)))
    pats.append(pat)
    
pats = np.array(pats)
total_price = np.dot(pats, prices)
total_effects = np.dot(pats, effects)
cond = ((total_effects >= X).sum(axis=1) == M)


ans = int(total_price[cond == 1].min())
print(ans)

Submission status: Runtime Error

Solution code:
N,M,X=[int(x) for x in input().rstrip().split()]
l=[]
for i in range(N):
  ca=[int(x) for x in input().rstrip().split()]
  l.append(ca)

cost=float('inf')
A=[0]*(M+2)
flag=1
ans=float('inf')
for i in range(2**N):
  flag=1
  cost=0
  for j in range(N):
    if i>>j & 1:
      now=l[N-j-1]
      cost+=now[0]
      for s in range(M):
        A[s]+=now[s+1]
  for t in range(M):
    if X<=A[t]:
      continue
    else:
      flag=0
      break
  if flag==1:
    ans=min(ans,cost)

  A=[0]*N
if ans==float('inf'):
  print(-1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
def main()
    n, m, x = map(int, input().split())
    ca = []
    for _ in range(n):
        ca.append(list(map(int, input().split())))
    result = 10**9
    for i in range(1, 2**n+1):
        work = 0
        j = 0
        temp = [0] * m
        for flag in bin(i)[2:].zfill(n):
            if flag == "1":
                work += ca[j][0]
                for k in range(1, m+1):
                    temp[k-1] += ca[j][k]
            j += 1
        flag = True
        for t in temp:
            if t < x:
                flag = False
                break
        if flag:
            result = min(result, work)
    if result == 10**9:
        print(-1)
    else:
        print(result)
main()

Submission status: Runtime Error

Solution code:
import copy

from collections import Counter

import numpy as np

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

dp = np.full([M, 2 * 10**5 + 1], 10**5, dtype=np.int32)
dp[:, 0] = 0

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

    for i, v in enumerate(a):
        p_dp = copy.deepcopy(dp)
        np.minimum(dp[i, v:], p_dp[i, :-v] + c, out=dp[i, v:])

p_ans = dp[:, X:]

ans_list = []
for i in range(M):
    ans_list += list(set(p_ans[i]))

C = sorted(Counter(ans_list).items())

for k, v in C:
    if v >= M:
        if k == 10**5:
            print(-1)
            break
        else:
            print(k)
            break
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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

coin = []
for i in range(1, m+1):
  for v in itertools.combinations(books, i):
    comb = list(v)
    result = np.sum(comb, axis = 0)
    if result[1] >= x and result[2] >= x and result[3] >= x:
      coin.append(result[0])

if len(coin) > 0:
  sorted(coin, reverse=False)
  print(coin[0])
else:
  print(-1)

Submission status: Runtime Error

Solution code:
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort(key=lambda x: x[0])
money = 0
ans = 0
for i in range(n):  
  c = A[i][0]
  a = A[i][1:]
  aa = min(a)
  money += c
  ans += aa
  if ans >= x:
    print(money())
    exit()
print(-1)

Submission status: Runtime Error

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


C =[]
A = {}

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

bestscore = 99999999999
def rec(n, score, money):
    global bestscore
    if n==N: return
    rec(n+1, score[:], money)

    money += C[n]
    for i in range(M):
        score[i] += A[n][i]
    

    for i in range(M):
        if score[i] < X:
            rec(n+1, score[:], money)
            return
    bestscore = min(bestscore, money)

score = [0 for i in range(N)]

rec(0, score, 0)
if bestscore == 99999999999:
    print(-1)
else:
    print(bestscore)

Submission status: Runtime Error

Solution code:
import itertools
import copy
n,m,x = map(int,input().split())
ans = [0 for i in range(m)]
books = []
answer = 1000000000000000000000
for i in range(n):
    books.append(list(map(int,input().split())))
for i in range(n):
    stock = list(list(itertools.combinations([num for num in range(n)], i+1)))
    for j in stock:
        cost = 0
        ans = [0 for i in range(m)]
        for k in j:
            for e,l in enumerate(books[k]):
                if e == 0:
                    cost += l
                else:
                    ans[e-1] += l
            if min(ans) >= x and cost < answer:
                answer = copy.deepcopy(cost)
if answer = 1000000000000000000000:
    print(-1)
else:
    print(answer)

Submission status: Runtime Error

Solution code:
n, m, x = map(int, input().split())
sL = [0]*m
bL = []
for i in range(n):
    book = list(map(int, input().split()))
    bL.append(book)


def fullS(currentL, index, allP):
    if index > len(currentL):
        if min(currentL) >= x:
            return allP
        else:
            return -1
    else:
        if min(currentL) >= x:
            return allP
        else:
            op1 = fullS(currentL, index+1, allP)
            newP = 0
            newL = []
            for i in range(len(bL[index])):
                if i == 0:
                    newP = allP+bL[index][i]
                else:
                    newL.append(currentL[i-1]+bL[index][i])
            op2 = fullS(newL, index+1, newP)
            if op1 == -1 and op2 == -1:
                return -1
            elif op1 == -1:
                return op2
            elif op2 == -1:
                return op1
            else:
                return min(op1, op2)
                


print(fullS(sL, 0, 0))

Submission status: Runtime Error

Solution code:
from itertools import permutations 

n,m,x = [int(x) for x in input().strip().split()]

cost = []
mat = []
res = 10**20

tot = [0 for i in range(m)]

for i in range(n):
    arr = [int(x) for x in input().strip().split()]
    cost.append(arr[0])
    mat.append(arr[1:])
    tot = [tot[i]+arr[i] for i in range(m)]

for to in tot:
    if to<x:
        flag=False
        break

if flag is False:
    print(-1)
else:
    perm = permutations([i for i in range(n)]) 

    for p in list(perm): 
        rem = [x for i in range(m)]
        comp = set([])
        curr_cost = 0
        for i in p:
            if len(comp)==m:
                break
            curr_cost+=cost[i]
            for j in range(m):
                rem[j]-=mat[i][j]
                if rem[j]<=0:
                    comp.add(j)

        if len(comp)==m:
            res = min(res,curr_cost)

    if res==10**20:
        res=-1
    print(res)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
N,M,X=map(int,input().split())
CA=[]
for i in range(N):
  CA.append(list(map(int,input().split())))
money=100000000000
count=1
for i in range(1,N):
  test=itertools.combinations(CA,i)
  for j in test:#組み合わせごとに計算
    pre_ans=np.sum(j, axis=0)
    if pre_ans[0]<money and np.all(pre_ans[1:]>=X):
      money=pre_ans[0]
      count=0
if count==0:
  print(money)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
from itertools import combinations


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

mtable = [None]*N
cs = []
for n in range(N):
    aa = list(map(int,input().split()))
    c = aa.pop(0)
    cs.append(c)
    ms = aa
    mtable[n] = ms
    

# print(mtable)
idxes = list(range(N))

prices = []
for i in range(1, N+1):
    for c in combinations(idxes, i):
        sums = [0]*M
        for idx in c:
            for i, m in enumerate(mtable[idx]):
                sums[i] += m
        if all(map(lambda x:x >= X, sums)):
            price = 0
            for idx in c:
                price += cs[idx]

            prices.append(price)
print(min(prices))

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
N,M,X=map(int,input().split())
CA=[]
for i in range(N):
  CA.append(list(map(int,input().split())))
#CA=sorted(CA, key=lambda x:sum(x[1:]))
money=100000000000000000000000000000
count=1
for i in range(1,N):
  test=itertools.combinations(CA,i)
  for j in test:#組み合わせごとに計算
    pre_ans=np.sum(j, axis=0)
    if pre_ans[0]<money and np.all(pre_ans[1:]>=X):
      money=pre_ans[0]
      count=0
if count==0:
  print(money)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
import itertools
min_price = 10**9
for k in range(n):
    for comb in itertools.combinations(range(m), k+1):
        sums = [0] * m
        price = 0
        for c in comb:
            price += C[c]
            for i in range(m):
                sums[i] += A[c][i]

#         print(comb)
#         print(sums)
        if sum([y >= x for y in sums]) == len(A):
            min_price = min(min_price, price)

if min_price == 10**9:
    print('-1')
else:
    print(min_price)

Submission status: Runtime Error

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

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

    mokuhyou = []
    for i in range(m):mokuhyou.append(0)
    c = 0
    price = 0


    for i in s:


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

    result = True
    for i in mokuhyou:
        if(i < x):result = False

    if(result):ans = min(ans, price)

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

Submission status: Runtime Error

Solution code:
n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(m):
	C,*A=map(int,input().split())
	c.append(C)
	a.append(A)

ans=[]
for i in range(2**n):
	A=[0]*m
	C=0
	lst=list(map(int,format(i,'b').zfill(n)))
	for j in range(m):
		if lst[j]==1:
			C+=c[j]
			for k in range(m):
				A[k]+=a[j][k]
	if all(elem>=x for elem in A):
		ans.append(C)
if len(ans):
	print(min(ans))
else:
	print(-1)

Submission status: Runtime Error

Solution code:
a, b, c, k = map(int, input().split())

ans = 0

k = k-a
if k >= a:
    ans += a
else:
    ans += k

k = k-b

if k >= c:
    ans -= k
else:
    ans -= c

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

n, m, unti = map(int, input().split())
ls = []
la = ls.append
for i in range(n):
    la(tuple(map(int, input().split())))
ans = int(1e10)
for x in range(1, len(ls)):
    for y in itertools.combinations(ls, x):
        if sum(x[1] for x in y) >= unti:
            if sum(x[2] for x in y) >= unti:
                if sum(x[3] for x in y) >= unti:
                    r = sum(x[0] for x in y)
                    if ans > r:
                        ans = r
print(ans if ans != int(1e10) else -1)

Submission status: Runtime Error

Solution code:
A, B, C, K = map(int, input().split())
a = A
b = K - A
c = K - B - A
p = [0 if x < 0 else x for x in [a, b, c]]
ans = 0
for i in range(3):
    if i == 0:
        ans += p[0]
    elif i == 2:
        ans -= p[2]
print(ans)