Problem:


Score : 300 points

Problem

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

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

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

Constraints

All values in input are integers.

1\leq N, M\leq 12

1\leq X\leq 10^5

1\leq C_i \leq 10^5

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

120

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

Sample Input 2

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

Sample Output 2

-1

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

Sample Input 3

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

Sample Output 3

1067



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


Sample output:
120

Submission status: Runtime Error

Solution code:
import itertools


def main():
    n, m, x = input_list()

    costs = []
    contents = [[] for i in range(m)]
    contents_with_index = [[] for i in range(m)]
    for i in range(n):
        b = input_list()
        costs.append(b[0])
        for index, c in enumerate(b[1:]):
            contents[index].append(c)
            contents_with_index[index].append((str(i), c))

    for c in contents:
        if sum(c) < x:
            print(-1)
            exit()

    results = [[] for i in range(m)]
    for index, c in enumerate(contents_with_index):
        for i in range(1, m+1):
            for cv in itertools.combinations(c, i):
                s = sum([num[1] for num in cv])
                if s >= x:
                    results[index].append(','.join([num[0] for num in cv]))

    ans = set(results[0])
    for r in results:
        ans &= set(r)

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

    print(min(usable_cost))


def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools

n,m,x=(int(x_) for x_ in input().split())
a,b,c,d = [],[],[],[]
a1 = 0
b1 = 0
c1 = 0
d1 = 0

for i in range(m):
    ai,bi,ci,di = map(int, input().split())
    a1 += ai
    b1 += bi
    c1 += ci
    d1 += di   
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)
if a1 < x:
    print(-1)
if b1 < x:
    print(-1)
if c1< x:
    print(-1)
if d1< x:
    print(-1)

Submission status: Runtime Error

Solution code:
import itertools

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


n = len(str_list)

b_pairs = []
for j in range(1, n+1):
    b_pairs += list(itertools.combinations(str_list, j))
    # 単に b_pairs += itertools.combinations(b, i) でも可

#print(len(b_pairs))
numl = []
for k in b_pairs:
  #print(k)
  num = 0
  ml = [0]*(M-1)
  for l in k:
    for d in range(1,M):
      ml[d-1] += l[d]
    num+=l[0]
  #print(ml)
  if min(ml) >= X:
    numl.append(num)
if len(numl) == 0:
  print(-1)
else:
  print(min(numl))

Submission status: Runtime Error

Solution code:
N,M,X=map(int,input().split())
li=[]
Ans=100001

for i in range(N):
    array=list(map(int,input().split()))
    li.append(array)

for j in range(2**N):
    b=bin(j)
    b=b[2:]
    b="0"*(N-len(b))+b
    
    
    c=0
    x=0
    y=0
    z=0

    for k in range(len(b)):
        if b[k]==str(1):
            c+=li[k][0]
            x+=li[k][1]
            y+=li[k][2]
            z+=li[k][3]
    if x>=X and y>=X and z>=X and Ans>c:
        Ans=c

if Ans==100001:
    print("-1")
else:
    print(Ans)

Submission status: Runtime Error

Solution code:
N, M, x= map(int, input().split())
dp=[[0 for i in range(N+1)] for j in range(M+1)]
nap = []
dp[0][0]=0
answ = [10]*M
for _ in range(N):
    nap.append(list(map(int, input().split()))) 

mon=[]
value=[]
for x in nap:
    mon.append(x[0])
for y in nap:
    value.append(y[1:])

ans = []
for i in range(N):
    for j in range(M):
        dp[i+1][j+1] = dp[i][j]+value[i][j]
for m in range(M):
    if answ[m] > ans[m]:
        print(-1)
        exit()


return dp[N][M]

Submission status: Runtime Error

Solution code:
N, M, x= map(int, input().split())
dp=[[0 for i in range(N+1)] for j in range(M+1)]
nap = []
dp[0][0]=0
answ = [10]*M
for _ in range(N):
    nap.append(list(map(int, input().split()))) 

mon=[]
value=[]
for x in nap:
    mon.append(x[0])
for y in nap:
    value.append(y[1:])

ans = []
for i in range(N):
    for j in range(M):
        dp[i+1][j+1] = dp[i][j]+value[i][j]
for m in range(M):
    if answ[m] > ans[m]:
        print(-1)
        exit()


return dp[N][W]

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
for i in range(N - 1):
    d = list(map(int, input().split()))
    CA = np.vstack((CA,d))
C = CA[:,0]
A = CA[:,1:]

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

Submission status: Runtime Error

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

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

if champ==100000:    
    print(-1)
else:
    print(champ)

Submission status: Runtime Error

Solution code:
import itertools

nums = [int(e) for e in input().split()]

list0 = []
for i in range(0, nums[0]):
    val = [int(e) for e in input().split()]
    list0.append(val)

A = []
A0 = list(range(0,nums[0]))
for i in range(0,nums[0]):
    for x in itertools.combinations(A0,i+1):
        A1 = list(x)
        A1 = list(set(A1))
        A.append(A1)

X = []
for i in range(0,len(A)):
    Y = [0] * (nums[1]+1)
    for j in range(0,len(A[i])):
        Y = [x + y for (x, y) in zip(Y,list0[A[i][j]])]
    if Y[1] >= nums[2] and Y[2] >= nums[2] and Y[3] >= nums[2]:
        X.append(Y[0])

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

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(m):
                s[k] += l[j][k]
    b = 1
    for k in range(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-1):
        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:
import itertools
import numpy as np

n, m, x= map(int, input().split())
a = [input().split() for l in range(n)]
npa=np.array(a, dtype=int)

hon=-1
for i in range(1,n+1):
  base = list(itertools.combinations(range(0,n),i))
#  print (base)
  
  for j in base:
    totalv=np.sum(npa[j,], axis=0)
#    print (totalv, min(totalv[1:-1]))
    
    if (min(totalv[1:-1]) >= x):
      if (hon == -1): hon=totalv[0]
      if (hon >= totalv[0]): hon=totalv[0]
#      print (hon)
      
print (hon)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
for i in range(N - 1):
    d = list(map(int, input().split()))
    CA = np.vstack((CA,d))
C = CA[:,0]
A = CA[:,1:]

C_set = []
for i in range(2 ** (N)):
    book = format(i, '0'+str(N)+'b')
    print(book)
    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())
li = [list(map(int, input().split())) for n in range(N)]
sum_X_i = 0
criterion = True
Answer = -1
for i in range(N):
  for j in range (1, M):
    sum_X_i += int(li[j][i])
  if sum_X_i >= X:
    sum_X_i = 0
    continue
  else:
    criterion = False
    break
print("-1" if criterion == False else "aiueo")

Submission status: Runtime Error

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

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

if flag:    
    print(-1)

Submission status: Runtime Error

Solution code:
def done(y,x,m):
	for i in range(m):
		if(y[i]<x):
			return 0
	return 1



n,m,x = list(map(int, input().split()))
a = []
co = []
for i in range(n):
	# c = int(input())
	# co.append(c)
	xt = list(map(int, input().split()))
	co.append(xt[0])
	a.append(xt[1:])

main = []

for i in range(n):
	su = 0
	for j in range(m):
		su += co[i]/a[i][j]
	main.append([su,i])

main = sorted(main, key = lambda t:t[0])

y = [0 for i in range(m)]
h = 0
ans = 0
while(h<n and (not done(y,x,m))):
	ans += co[main[h][1]]
	for i in range(m):
		y[i] += a[main[h][1]][i]
	h+=1

if(done(y,x,m)):
	print(ans)
else:
	print(-1)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
list=[l[0]]
num=0
while True:
  if l[list[num]-1] in list:
    break
  list.append(l[list[num]-1])
  num+=1
y=list.index(l[list[num]-1])
x=len(list)-y
ans=list[y:]
print(ans[(k-y)%x-1])
n,k=map(int,input().split())
l=list(map(int,input().split()))
list=[l[0]]
num=0
while True:
  if l[list[num]-1] in set(list):
    break
  list.append(l[list[num]-1])
  num+=1
y=list.index(l[list[num]-1])
x=len(list)-y
ans=list[y:]
print(ans[(k-y)%x-1])
提出情報

Submission status: Runtime Error

Solution code:
import pandas as pd
import numpy as np
n,m,x=map(int,input().split())
zen=np.array(list(map(int,input().split()) for _ in range(n)))
a=pd.Series(zen.sum(1))
df=pd.DataFrame(zen)
df=df.join(a)
df=df.sort_values(a)

p=df.iloc[-1]
df=df.drop(df.index[[-1]])
while all(p[1:]>=x):
  p+=df.iloc[-1]
print(p[0].sum())

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

n, m, x = map(int, input().split())
# clist2 = [[60, 2, 2, 4], [70, 8, 7, 9], [50, 2, 3, 9]]

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

test_list = []
test_list_num = list(range(1, n+1))

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 itertools
n,m,x=map(int,input().split())
l=[[0]]*n
ln=[0]*m
kan=0
for i in range(n):
  l[i]=list(map(int,input().split()))
  for j in range(m+1):
    if j==0:
      kan+=l[i][j]
    else:
      ln[j-1]+=l[i][j]
if sorted(ln)[0]<x:
  print(-1)
else:
  mkan=-1
  for i in range(n):
    itr=itertools.combinations(range(n),i)
    for comb in itr:
      kan=0
      ln=[0]*m
      for j in comb:
        kan+=l[int(j)][0]
        for ii in range(m):
          ln[ii]+=l[int(j)][ii+1]
      if sorted(ln)>=x:
        if mkan==-1 or mkan>kan:
          mkan=kan
  print(mkan)

Submission status: Runtime Error

Solution code:
N,M,X=map(int,input().split())
li=[]
Ans=100001

for i in range(N):
    array=list(map(int,input().strip().split()))
    li.append(array)

for j in range(2**N):
    b=bin(j)
    b=b[2:]
    b="0"*(N-len(b))+b
    
    
    c=0
    x=0
    y=0
    z=0

    for k in range(len(b)):
        if b[k]==str(1):
            c+=li[k][0]
            x+=li[k][1]
            y+=li[k][2]
            z+=li[k][3]
    if x>=X and y>=X and z>=X and Ans>c:
        Ans=c

if Ans==100001:
    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))
l=[]*n
for i in range(n):
    b=[0,0]
    b[0]+=i+1
    b[1]+=a[i]
    l.append(b)
c=0
ne=0
l1=[0]*n
while True:
    if c==k:
        print(l[ne][1])
        exit()
    ne+=-ne+l[ne][1]-1
    c+=1
    if l1[ne]==0:l1[ne]+=1
    else:break

roop_c=0
while True:
    if c+roop_c==k:
        print(l[ne][1])
        exit()
    if l1[ne]==1:l1[ne]+=1
    else:break
    ne+=-ne+l[ne][1]-1
    roop_c+=1

re=(k-c)%roop_c
if re==0:print(l[ne][0])
else:
    for i in range(re):
        if i==re-1:print(l[ne][1])
        ne+=-ne+l[ne][1]-1

Submission status: Runtime Error

Solution code:
def seek(achieve0,cost0,num1):
    for i in range(num1,booknum):
        for j in range(alnum):
            achieve0[j] -= int(bookinfo[i][j+1])
            judge1 = True
            for i in range(alnum):
                if achieve[i] < objective:
                    judge1 = False
            if(judge1):
                cost0-=int(bookinfo[i][0])
                num1+=1
                global achieve1
                achieve1 = achieve0
                if(num1<booknum):
                    seek(achieve0,cost0,num1)
            else:
                costs.append(cost0)
                cost0=cost
                num1+=1
                if(num1<booknum):
                    seek(achieve1,cost0,num1)



if __name__ == '__main__':
    list0 = input().split(" ")
    global bookinfo
    bookinfo = []
    global alnum
    alnum = int(list0[0])
    global booknum
    booknum = int(list0[1])
    objective = int(list0[2])
    global cost
    cost = 0
    global costs
    costs = []
    global achieve
    achieve = []
    judge = True
    for i in range(booknum):
        bookinfo.append(input().split(" "))
        cost+=int(bookinfo[i][0])
    for i in range(alnum):
        achieve.append(0)
    for i in range(1,alnum+1):
        for j in range(booknum):
            achieve[i-1]+=int(bookinfo[j][i])
    for i in range(len(achieve)):
        if achieve[i]<objective:
            judge = False
    if judge==False:
        print(-1)
    else:
        for i in range(booknum):
            seek(achieve,cost,0)
        print(min(costs))

Submission status: Runtime Error

Solution code:
import itertools

nums = [int(e) for e in input().split()]

list0 = []
for i in range(0, nums[0]):
    val = [int(e) for e in input().split()]
    list0.append(val)

A = []
A0 = list(range(0,nums[0]))
for i in range(0,nums[0]):
    for x in itertools.combinations(A0,i+1):
        A1 = list(x)
        A1 = list(set(A1))
        A.append(A1)

X = []
for i in range(0,len(A)):
    Y = [0] * (nums[1]+1)
    for j in range(0,len(A[i])):
        Y = [x + y for (x, y) in zip(Y,list0[A[i][j]])]
    X.append(Y)

B = []
for i in range(0,len(X)):
    if X[i][1] >= nums[2] and X[i][2] >= nums[2] and X[i][3] >= nums[2]:
        B.append(X[i][0])

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

Submission status: Runtime Error

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


a=[i for i in range(1,2**n+1)]
b=[list(format(i,'015b'))[-(n):] for i in a]
ans=0
c=-1
for s in range(2**n):
    list_01=b[s]
    learn_rate=[0 for i in range(n)]
    cost=0
    
    
    for i in range(n):
        f=list_01[i]
        f=int(f)
        if f==1:
            for h in range(m):      
#                 print(lis[i][1][h])
                learn_rate[h]+=lis[i][1][h]
            cost+=lis[i][0]
    flg=1
    for i in range(m):
        if learn_rate[i]<x:
            flg=0
    if flg==1:
        if c==-1:
            c=cost
        else:   
            c=min(c,cost)
print(c)

Submission status: Runtime Error

Solution code:
import numpy as np

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

sumListC = np.sum(listC, axis=0)
tmp = list(filter(lambda x: x < X, sumListC[1:]))
if (len(tmp) > 0):
    print(-1)
    exit()
listC.sort(key=lambda x: x[0])
ansList = []
count = 0
for i in range(N):
    ansList.append(listC[i])
    sumListC = np.sum(ansList, axis=0)
    tmp = list(filter(lambda x: x < X, sumListC[1:]) ) 
    count += 1 
    if (len(tmp) == 0):
        break
for i in range(count):
    tmp = ansList.pop(0)
    sumListC = np.sum(ansList, axis=0)
    tmp2 = list(filter(lambda x: x < X, sumListC[1:] ) ) 
    if (len(tmp2) > 0):
        ansList.append(tmp)
print(np.sum(ansList, axis=0)[0])

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

n, m, x= map(int, input().split())
a = [input().split() for l in range(n)]
npa=np.array(a, dtype=int)

#print (npa)

hon=-1
for i in range(1,n+1):
  base = list(itertools.combinations(range(0,n),i))
#  print (base)
  
  for j in base:
    totalv=np.sum(npa[j,], axis=0)
#    print (totalv, min(totalv[1:-1]))
    
    if (min(totalv[1:-1]) >= x):
      if (hon < 0): hon=totalv[0]
      if (hon >= totalv[0]): hon=totalv[0]
#      print (hon)
      
print (hon)

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:
        if j>=X for j in K:
            m.append(sum)
        return j>=X for j in K
            

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


a=[i for i in range(1,2**n+1)]
b=[list(format(i,'012b'))[-(n):] for i in a]
ans=0
c=-1
for s in range(2**n):
    list_01=b[s]
    learn_rate=[0 for i in range(n)]
    cost=0
    
    
    for i in range(n):
        f=list_01[i]
        f=int(f)
        if f==1:
            for h in range(m):      
#                 print(lis[i][1][h])
                learn_rate[h]+=lis[i][1][h]
            cost+=lis[i][0]
    flg=1
    for i in range(m):
        if learn_rate[i]<x:
            flg=0
    if flg==1:
        if c==-1:
            c=cost
        else:   
            c=min(c,cost)
print(c)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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

# l = list(range(0, n))
# print(l)

l = []
for i in range(n):
    l.append(list(map(int, input().split())))
    
# print(l)

value_list = []
min_value = -1
for v in itertools.permutations(l):
    lll = np.array([0] * (m + 1))
    for ll in v:
        # print(lll)
        # print(np.array(ll))
        # print(lll + np.array(ll))
        lll = lll + np.array(ll)
        # print(min(lll[1:]))
        if min(lll[1:]) >= x:
            # print(lll[0])
            value_list.append(lll[0])
            break

print(min(value_list))

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
n,m,x=map(int,input().split())
a=[]
b=[0]*m
skill=np.array([b])
ans=[]
money=0
for _ in range(n):
    a.append(list(map(int,input().split())))
for i in range(1,n+1):
    for j in itertools.combinations_with_replacement(range(1,n+1),i):
        for k in range(len(j)):
            money+=a[j[k]-1][0]
            skill+=np.array([a[j[k]-1][1:m+1]])
        if all([i>=x for i in skill[0]]):
            ans.append(money)
        money=0
        skill=np.array([b])
print(min(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import copy
N, M, X = map(int, input().split())
C = np.zeros(N, dtype=np.uint16)
A = np.zeros([N, M], dtype=np.uint16)
skills = np.zeros(M, dtype=np.uint16)
sum_skills = np.zeros(M, dtype=np.uint32)
sum_A = np.zeros(N, dtype=np.uint32)

for n in range(N):
    CA = list(map(np.uint16, input().split()))
    C[n] = CA[0]
    A[n] = CA[1:]
    sum_skills += CA[1:]
    sum_A[n] = sum(CA[1:])


def check_skills(skills):
    return np.all(skills >= X)


if np.all(sum_skills >= X):
    pass
else:
    print("-1")
    exit()

results = []
book_sorted = np.argsort(sum_A)
for n in range(M):
    result = ([n], C[n].copy(), A[n].copy())
    results.append(result)

min_cost = np.sum(C)

while len(results) > 0:
    result = results.pop(0)
    if check_skills(result[2]):
        min_cost = min(min_cost, result[1])
    elif result[1] > min_cost:
        continue
    else:
        max_idx = max(result[0])
        for idx in range(max_idx+1, N):
            (idxes, total_cost, skill_values) = copy.copy(result)
            idxes = idxes + [idx]
            total_cost = total_cost + C[idx]
            skill_values = skill_values + A[idx]
            results.append((idxes, total_cost, skill_values))

print(min_cost)

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)
# import itertools
# import statistics
# import numpy as np
# n = int(input())
# a, b, c, k = 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()))
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])
# print(a_sorted)

money = 0
point = [0]*m
over = [0]*m
for i in range(n):
    fin = True
    money += a_sorted[i][0]
    for j in range(m):
        point[j] += a_sorted[i][j+1]
    for j in range(m):
        if point[j] < x:
            fin = False
        else:
            over[j] = point[j]-x
    if fin:
        k = []
        for i in range(n):
            kouho = True
            for j in range(m):
                if a_sorted[i][j+1] > over[j]:
                    kouho = False
            if kouho:
                k.append(i)
        k.sort(reverse=True)
        if len(k) != 0:
            for i in range(len(k)):
                for j in range(m):
                    point[j] -= a_sorted[i][j+1]
                    if point[j] < x:
                        print(money)
                        exit()
                money -= a_sorted[i][0]
        # print(over)
        for j in range(m):
            print(money)
            exit()
    # print(check)
print(-1)

Submission status: Runtime Error

Solution code:
from itertools import combinations
 
N, M, X = list(map(int,input().split()))
A = []
for i in range(N):
  A.append(list(map(int,input().split())))
sum = []
subsets=[]
for i in range(len(A) + 1):
    for c in combinations(A, i):
        subsets.append(list(c))
 
for i in subsets:
  tmp = [0]*(M+1)
  if len(i) == 1:
    sum.append(i[0])
  elif len(i) == 0:
    sum.append([0]*(M+1))
  else:
    for j in i:
      tmp = list(map(lambda a,b: a + b, tmp,j))
    sum.append(tmp)
    
min_price = 999999999999999
 
for i in sum:
  t = 0
  for j in range(len(i)):
    if j==0:
      pass
    elif X > i[j]:
      t = 1
      break
  if t == 0
    min_price = min(min_price, i[0])
 
if min_price == 999999999999999:
  print(-1)
else:
  print(min_price)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
for i in range(N - 1):
    d = list(map(int, input().split()))
    CA = np.vstack((CA,d))
C = CA[:,0]
A = CA[:,1:]

C_set = []
for i in range(2 ** (M+1)):
    book = format(i, '0'+str(N)+'b')
    S = [0] * M
    CC = 0
    for j in range(M):
        if book[j] == "1":
            S = S + A[j,:]
            CC += C[j]
    if 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:
from itertools import combinations
 
N, M, X = list(map(int,input().split()))
A = []
for i in range(N):
  A.append(list(map(int,input().split())))
sum = []
subsets=[]
for i in range(len(A) + 1):
    for c in combinations(A, i):
        subsets.append(list(c))
 
for i in subsets:
  tmp = [0]*(M+1)
  if len(i) == 1:
    sum.append(i[0])
  elif len(i) == 0:
    sum.append([0]*(M+1))
  else:
    for j in i:
      tmp = list(map(lambda a,b: a + b, tmp,j))
    sum.append(tmp)
    
min_price = 101010101010101010101010
 
for i in sum:
  t = 0
  for j in range(len(i)):
    if j==0:
      pass
    elif X > i[j]:
      t = 1
      break
  if t == 0
    min_price = min(min_price, i[0])
 
if min_price == 101010101010101010101010:
  print(-1)
else:
  print(min_price)

Submission status: Runtime Error

Solution code:
import itertools

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


n = len(str_list)

b_pairs = []
for j in range(1, n+1):
    b_pairs += list(itertools.combinations(str_list, j))
    # 単に b_pairs += itertools.combinations(b, i) でも可

#print(len(b_pairs))
numl = []
for k in b_pairs:
  #print(k)
  num = 0
  a = 0
  b = 0
  c = 0
  for l in k:
    a += l[1]
    b += l[2]
    c += l[3]
    num+=l[0]
  if a>=X and b >=X and c >=X:
    numl.append(num)
if len(numl) == 0:
  print(-1)
else:
  print(min(numl))

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, X = map(int, input().split())
CA = list(map(int, input().split()))
for i in range(N - 1):
    d = list(map(int, input().split()))
    CA = np.vstack((CA,d))
C = CA[:,0]
A = CA[:,1:]

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

a=list(map(int,input().split()))


if(len(set(a))== len(a)):
    if(k<10**9):
        sen=1
        for i in range(k):
            sen=a[sen-1]
        print(sen)
        exit()
    else:
        sen=1
        for i in range(n-k):
            sen=a.index(sen)
        print(sen)
        exit()
s=[]
sen=1
for i in range(k):
    if(sen in s):
        break
        
    else:
        s.append(sen)
        sen=a[sen-1]

#print(s)

k=k%len(s)
if(sen!=1):
    k-=1
#sen=1
for i in range(k):
    sen=a[sen-1]
print(sen)

Submission status: Runtime Error

Solution code:
import numpy as np
import copy
N, M, X = map(int, input().split())
C = np.zeros(N, dtype=np.uint16)
A = np.zeros([N, M], dtype=np.unt16)
skills = np.zeros(M, dtype=np.uint16)
sum_skills = np.zeros(M, dtype=np.uint32)
sum_A = np.zeros(N, dtype=np.uint32)

for n in range(N):
    CA = list(map(int, input().split()))
    C[n] = CA[0]
    A[n] = CA[1:]
    sum_skills += CA[1:]
    sum_A[n] = sum(CA[1:])


def check_skills(skills):
    return np.all(skills >= X)


if np.all(sum_skills >= X):
    pass
else:
    print("-1")
    exit()

results = []
book_sorted = np.argsort(sum_A)
for n in range(M):
    result = ([n], C[n].copy(), A[n].copy())
    results.append(result)

min_cost = np.sum(C)

while len(results) > 0:
    result = results.pop(0)
    if check_skills(result[2]):
        min_cost = min(min_cost, result[1])
    elif result[1] > min_cost:
        continue
    else:
        max_idx = max(result[0])
        for idx in range(max_idx+1, N):
            (idxes, total_cost, skill_values) = copy.copy(result)
            idxes = idxes + [idx]
            total_cost = total_cost + C[idx]
            skill_values = skill_values + A[idx]
            results.append((idxes, total_cost, skill_values))

print(min_cost)

Submission status: Runtime Error

Solution code:
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9