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: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
INF = 10 ** 10
ans = INF


def rec(A, C, X, idx, ability, sum_):
    if idx == len(A):
        for i in range(len(ability)):
            if ability[i] < X:
                break
        else:
            global ans
            ans = min(sum_, ans)
    else:
        # not buy
        rec(A, C, X, idx+1, ability, sum_)
        M = len(A[0])
        import copy 
        for i in range(M):
            ability[i] += A[idx][i]
        rec(A, C, X, idx+1, copy.copy(ability), sum_+C[idx])


def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    for i in range(N):
        lists = [int(c) for c in input().split()]
        ci = lists[0]
        ai = lists[1:]
        C.append(ci)
        A.append(ai)

    ability = [0] * M
    rec(A, C, X, 0, ability, 0)

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

    
    



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

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

minnum = (10**5) * 12

for i in range(1, n + 1):
    tmp = list(itertools.combinations(c, i))
    # print(tmp)
    for item in tmp:
        t = list(zip(*item))
        xs = [sum(t[j]) if sum(t[j]) >= x else False for j in range(1, m + 1)]
        if False not in xs and sum(t[0]) < minnum:
            minnum = sum(t[0])
if minnum != (10**5) * 12:
    print(minnum)
else:
    print(-1)

Submission status: Wrong Answer

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):
		if(a[i][j] != 0):
			su += co[i]/a[i][j]
		else:
			su += 0
	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: Wrong Answer

Solution code:
import numpy as np

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

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

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

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

idx_c = list(np.argsort(-1 * np.array(c)))
c_sum = sum(c)

for i in idx_c:
    u_tmp = [u[j] - a[i][j] for j in range(m)]
    if can_reach_the_goal(u_tmp, x):
        c_sum -= c[i]
        u = u_tmp

print(c_sum)

Submission status: Wrong Answer

Solution code:
n,m,x = [int(i) for i in input().split()]
bk = []
for _ in range(n):
   bk.append([int(i) for i in input().split()])
rp = 2**n 
ans = 1000000
for i in range(rp):
   rikai = [0]*m
   mon = 0
   for j in range(n):
      if i>>j & 1:
         mon += bk[j][0]
         for k in range(m):
            rikai[k] += bk[j][k+1]
   flag = True
   for j in rikai: #この組み合わせでいいか
      if j < x:
         flag = False
         break
   if flag:
      ans = min(ans,mon)
if ans == 1000000:
   ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np

N,M,X=map(int, input().split())
list_=[list(map(int, input().split())) for _ in range(N)]
gokei=X
cost=100001
list_C=[]

for i in range(N):
	list_C=np.array(list(combinations(list_,N-i)))
	count=0
	#print(list_C)
	for h in range(len(list_C)):
		if all(np.sum(list_C[h], axis=0)[1:]>=X):
			if np.sum(list_C[h], axis=0)[0]<cost:
				cost=np.sum(list_C[h], axis=0)[0]
			#print(np.sum(list_C[h], axis=0),cost)
			count+=1
	if count==0:
		break

print(cost if cost<100001 else -1)

Submission status: Wrong Answer

Solution code:
#-*- utf-8 -*-

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

books.sort(key = lambda x: x[0])
for i in range(M - 1):
    books.sort(key = lambda x: x[i + 1], reverse = True)

def learn(index, progress, sum_money):
    if 0 == len(list(filter(lambda x: x < X, progress))):
        return sum_money
    elif N <= index:
        return -1
    else:
        sum_money += books[index][0]
        for i in range(M):
            progress[i] += books[index][i+1]
        return learn(index + 1, progress, sum_money)

print(learn(0, [0 for i in range(M)], 0), flush = True)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
k1=[0]*n
k=[0]*n
c=[0]*n
for d in range(n):
    k1[d]=list(map(int,input().split()))
    k[d]=k1[d][1:len(k1[d])]
    c[d]=k[d][0]
t=[0]*n
s=[0]*n
for al in range(n):
    flag=[0]*n
    for i in range(al,n):
        if s==0:
            for x1 in range(m):
                flag[x1]+=k[d][x1]
            for f in flag:
                if f<x:
                    break
                else:
                    s[al]+=1
            t[al]+=c[al]
t2=sorted(t)
j=0
for ds in s:
    if ds!=0:
        j+=1
if j==0:
    print(-1)
else:
    print(min(t2))

Submission status: Wrong Answer

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


def rec(i: int, rikai, res):
  
  #print(i, rikai, res)
  if i == N:
    return res+10000000000000
  
  use_rikai = [ rikai[j] - arr[i][j+1] for j in range(M) ]
  
  flag = True
  for r in use_rikai:
    if r <= 0: continue
    else: flag = False
  if flag:
    return res+arr[i][0]
  
  return min(rec(i+1, use_rikai, res+arr[i][0]), rec(i+1, rikai, res))

rikai = [X for j in range(M)]
res = rec(0, rikai, 0)
if res >= +10000000000000:
  print(-1)
else: print(res)

Submission status: Wrong Answer

Solution code:
import itertools
A,B,C = map(int,input().split())


a=[]
for i in  range(A):
    a.append(list(map(int,input().split())))
print(a)
a.sort()   
print(a)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,x=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int, input().split())))
l.sort()
sum=[]
sum.append([0]*(m+1))
sum=np.array(sum)
l=np.array(l)
for i in l:
  sum=np.insert(sum, len(sum), sum[len(sum)-1]+i, axis=0)
#print(sum)
ans=sum[len(sum)-1][0]+1
for i in range(len(sum)-1):
  for j in range(i+1,len(sum)):
    tmp=sum[j]-sum[i]
    if (tmp[1:] >=x).all():
      if ans>tmp[0]:
        ans=tmp[0]
if ans==sum[len(sum)-1][0]+1:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import array

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


c=[]
d=[0]*(m+1)
for i in range(n):
    c1=array(list(map(int,input().split())))
    c.append(c1)
    d+=c1


#print(c)
c.sort(key=lambda x: x[0], reverse=True)
#print(c)
#print(d)

if(False in [x<=i for i in d[1:]]):
   print(-1)
   exit()

#print(d[0])
f=d
for i in range(n):
    g=d
    for j in range(n-i):
        e=g-c[j]
        #print(e)
        if(False not in [x<=i for i in e[1:]]):
            g=e
    if(f[0]<g[0]):
        continue
    else:
        f=g
print(f[0])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import itertools as it


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

    book = []

    for n in range(N):
        book.append(list(map(int, input().split())))
    
    ok = False

    for n in range(1, N+1):
        if ok:
            break
        mini = 10**15
        for v in it.combinations([x for x in range(1, N+1)], n):

            us = [0]*(M+1)
            flag = True
            for i in list(v):
                for j in range(1, M+1):
                    us[j] += book[i-1][j]
            for i in us[1:]:
                if i < X:
                    flag = False
                    break

            if flag:
                ok = True
                temp = 0
                for i in v:
                    temp += book[i-1][0]
                if mini > temp:
                    mini = temp
    
    if ok:
        print(mini)
    else:
        print(-1)
                    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

#参考書数、理解度目標　参考書ステータス　今とってる参考書　理解度合計　値段合計
def comall(depth,n,x,a,usum,vsum):
  allok = True
  for i in range(1,len(usum)):
    #print(i, end = " ")
    if usum[i] < x:
      allok = False
      break
  #print()
  if allok:
    #print(vsum)
    return vsum
  else:
    #print(depth)
    if depth >= n:
      return 1000000
    else:
      v1 = comall(depth+1,n,x,a,copy.copy(usum),vsum)#i番目の参考書は買わない
      for i in range(1,len(usum)):
        usum[i] += a[depth][i]
      v2 = comall(depth+1,n,x,a,copy.copy(usum),vsum+a[depth][0])#i番目の参考書は買う
      return min(v1,v2)


def main():
  nmx = input().split()
  n = int(nmx[0])
  m = int(nmx[1])
  x = int(nmx[2])

  c = []
  for i in range(n):
    cn = list(map(lambda x:int(x), input().split() ))
    c.append(cn)
    
  ans = comall(0,n,x,c,[0]*(m+1),0)
  if ans == 1000000:
    print(-1)
  else:
    print(ans)
    
main()

Submission status: Wrong Answer

Solution code:
#-*- utf-8 -*-

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

books.sort(key = lambda x: x[0])
for i in range(M - 1):
    books.sort(key = lambda x: x[i + 1], reverse = True)

def learn(index, progress, sum_money):
    if 0 == len(list(filter(lambda x: x < X, progress))):
        return sum_money
    elif N <= index:
        return -1
    else:
        sum_money += books[index][0]
        print(sum_money)
        for i in range(M):
            progress[i] += books[index][i+1]
        return learn(index + 1, progress, sum_money)

print(learn(0, [0 for i in range(M)], 0), flush = True)

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort(reverse=True)
#print(A)
tmp=[0]*M
for i in range(1,M+1):
  for j in range(N):
    tmp[i-1]+=A[j][i]
if min(tmp)<X:
  print(-1)
  exit()
#print(tmp)
NES=[i for i in range(N)]
for i in range(N):
  C = [x - y for (x, y) in zip(tmp, A[i][1:])]
  if min(C)>=X:
    tmp=C
    NES.remove(i)
'''
print(NES)
NES=[i for i in range(N)]
for i in range(1,M+1):
  for j in range(N):
    if tmp[i-1]-A[j][i]>=X:
      tmp[i-1]-=A[j][i]
      NES.remove(j)
NES=set(NES)
NES=list(NES)
print(NES)
'''
ans=0
for i in range(len(NES)):
  ans+=A[NES[i]][0]
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N,M,X = map(int, input().split())
S = []
N_list = list(range(1,N+1))
for _ in range(N):
    c = list(map(int, input().split()))
    S.append(c)
min = 100000
for i in range(1,N+1):
    c = list(itertools.combinations(N_list, i))
    for v in c:
        A = [0]*M
        money = 0
        flag =0
        for i in range(len(v)):
            book = v[i]
            book_list = S[book-1]
            money += book_list[0]
            for t in range(M):
                A[t] += book_list[t+1]
        for s in A:
            if s<X:
                flag = 1
                break
        if flag != 1:
            if money <= min:
                min = money

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

Submission status: Wrong Answer

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)[0]>=x:
        if mkan==-1 or mkan>kan:
          mkan=kan
  print(mkan)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
import heapq

n,m,y = map(int, input().split())
cost=[]
for i in range(n):
    cost.append(list(map(int, input().split())))
    
cost_ar=np.array(cost)
iterable=list(range(n))
combinations=[]
for i in range(2,n+1):
    combinations.append(list(itertools.combinations(iterable,i)))
    
ans=[]

for i in combinations:
    for j in i:
        x=np.array([0]*(m+1))
        for k in j:
            x+=cost_ar[k]
        heapq.heappush(ans,x.tolist())
        
while len(ans) > 0:       
    temp = heapq.heappop(ans)
    for i in range(1,len(temp)):
        if temp[i]<y:
            break
    if i==len(temp)-1:
        print(temp[0])
        break
    if len(ans)==0:
        print(-1)

Submission status: Wrong Answer

Solution code:
N,M,X = map(int,input().split(" "))
C = {}
S = {}
A = {}
para = [0]*M
money = 0
flag = 1
for i in range(N):
    tosyo = [int(i) for i in input().split(" ")]
    C[i] = tosyo[0]
    del tosyo[0]
    A[i] = tosyo
    S[i] = sum(tosyo)/C[i]
    
S_ = sorted(S.items(), key = lambda x : x[1],reverse=True)
# print(S_)
for s in S_:
    i = s[0]
    money += C[i]
    for j in range(M):
        para[j] += A[i][j]
    check = sum([1 for p in para if p>=X])
    if check==M:
        flag = 0
        break
    
if flag == 0:
    print(money)
else:
    print(-1)

Submission status: Wrong Answer

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

grasp = []  # 理解度
for i in range(m):
  grasp.append(0)

  cost = 0
  check = -1
for i in range(n):
  li = input().split()  # 入力リスト
  li_int = [int(str) for str in li]  # int型
  cost += li_int[0]  # 金額を足す
  del li_int[0]  # リストから金額削除
  grasp = [x + y for (x, y) in zip(grasp, li_int)]
  if min(grasp) >= x:
    check = cost
    break
    
print(check)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

# print(N, M, X)
# print(C_A_list)

# N, M, X = 3, 3, 10
# C_A_list = [np.array([60, 2, 2, 4]),
#             np.array([70, 8, 7, 9]),
#             np.array([50, 2, 3, 9])]

price_min = -1
for i in range(1, M + 1):
    for j in itertools.combinations(C_A_list, i):
        # print(j)
        sum_list = sum(j)
        if min(sum_list[1:]) >= X:
            if price_min > 0:
                prince_min = min(price_min, sum_list[0])
            else:
                price_min = sum_list[0]

print(price_min)

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x=map(int,input().split())
l=[tuple(map(int,input().split())) for _ in range(n)]
a=[0]*m
total=m*(10**5)
for i in range(1, n+1):
    for j in itertools.combinations(range(n), i):
        num=0
        a=[0]*m
        for k in j:
            num+=l[k][0]
            for m_ in range(m):
                a[m_] += l[k][m_+1]
        if len(list(filter(lambda x_: x <= x_, a))) == m:
            total = min(num, total)
print(total)

Submission status: Wrong Answer

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


def rec(i: int, rikai, res):
  
  #print(i, rikai, res)
  if i == N:
    return res+1000000000
  
  use_rikai = [ rikai[j] - arr[i][j+1] for j in range(M) ]
  
  flag = True
  for r in use_rikai:
    if r <= 0: continue
    else: flag = False
  if flag:
    return res+arr[i][0]
  
  return min(rec(i+1, use_rikai, res+arr[i][0]), rec(i+1, rikai, res))

rikai = [X for j in range(M)]
res = rec(0, rikai, 0)
if res >= 1000000000:
  print(-1)
else: print(res)

Submission status: Wrong Answer

Solution code:
import copy

#参考書数、理解度目標　参考書ステータス　今とってる参考書　理解度合計　値段合計
def comall(depth,n,x,a,usum,vsum):
  allok = True
  for i in usum:
    #print(i, end = " ")
    if i < x:
      allok = False
      break
  #print()
  if allok:
    #print(vsum)
    return vsum
  else:
    #print(depth)
    if depth >= n:
      return 1000000
    else:
      v1 = comall(depth+1,n,x,a,copy.copy(usum),vsum)#i番目の参考書は買わない
      for i in range(len(usum)):
        usum[i] += a[depth][i]
      v2 = comall(depth+1,n,x,a,copy.copy(usum),vsum+a[depth][0])#i番目の参考書は買う
      return min(v1,v2)


def main():
  nmx = input().split()
  n = int(nmx[0])
  m = int(nmx[1])
  x = int(nmx[2])

  c = []
  for i in range(n):
    cn = list(map(lambda x:int(x), input().split() ))
    c.append(cn)
    
  ans = comall(0,n,x,c,[0]*(m+1),0)
  if ans == 1000000:
    print(-1)
  else:
    print(ans)
    
main()

Submission status: Wrong Answer

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

for i in range(2**N):
  cost = 0
  a = [0 for j in range(M)]
  for n in range(N):
    if format(i, '#012b')[-n] == "0":
      cost += C[n]
      a = [l+r for l,r in zip(a,A[n])]
  else:
    if all([a_ >= X for a_ in a]) and (min_value == -1 or cost<min_value):

      min_value = cost
print(min_value)

Submission status: Wrong Answer

Solution code:
N,M,X = map(int,input().split(" "))
C = {}
S = {}
A = {}
para = [0]*M
money = 0
flag = 1
for i in range(N):
    tosyo = [int(i) for i in input().split(" ")]
    C[i] = tosyo[0]
    del tosyo[0]
    A[i] = tosyo
    S[i] = sum(tosyo)/C[i]
    
S_ = sorted(S.items(), key = lambda x : x[1],reverse=True)
# print(S_)
for s in S_:
    i = s[0]
    money += C[i]
    for j in range(M):
        para[j] += A[i][j]
    check = sum([1 for i in para if i>=X])
    if check==M:
        flag = 0
        break
    
if flag == 0:
    print(money)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
S= input().split()
n=int(S[0])
m=int(S[1])
x=int(S[2])
a=[m+1]
book = np.zeros((m+1,n))
total = np.zeros(m+1)

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

total =  np.sum(book, axis=1)
ans =total.copy()
b = total.copy()

for l in range(n):
    b = ans.copy()
    for j in range(m):
        b[j+1] -= book[j+1][l]
        if b[j+1] < x:
            break
        if j ==m -1:
            b[0] -= book[0][l]
            ans = b.copy()
print(ans[0])

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools

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


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


nums = []
for i in range(n):
    nums.append(i)

temp = []
for i in range(1, n+1):
    for v in itertools.combinations(nums, i):
        rikaido = [0] * (m+1)
        for j in range(len(v)):
            for k in range(m+1):
                rikaido[k] += a_do[v[j]][k]

        temp.append(rikaido)

minimum = 10**20
for i in range(len(temp)):
    for j in range(1, m+1):
        if temp[i][j] < x:
            break
        minimum = min(minimum, temp[i][0])

# if(minimum == 10**20):
#     print(-1)
# else:
#     print(minimum)

print(-1)

Submission status: Wrong Answer

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

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

kingaku = 0
memos = [[0] * (m+2) for _ in range(n)]


def rec(i, rikaido, kingaku):
    
    # print('i, rikaido, kingaku', i, rikaido, kingaku)
    # print('終了条件', [i >= x for i in rikaido])
    # 終了条件：成功：全ての理解度がx以上になっている
    if all([i >= x for i in rikaido]):
        return kingaku

    # 終了条件：失敗；n冊目までチェックし終えた
    if i == n:
       return MAX

    return min(rec(i+1, rikaido, kingaku), rec(i+1, [u+t for u, t in zip(rikaido, datas[i][1:])], kingaku+datas[i][0]))


ans = rec(-1, [0] * m , 0)
if ans == MAX:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
cnt = [i for i in range(n)]
ans = 10**6
ok = False
for i in range(1,n+1):
    for conb in itertools.combinations(cnt, i):
        z = [0]*(m+1)
        for j in conb:
            for k in range(m+1):
                z[k] = z[k] + ca[j][k]
            if sum(l >= x for l in z[1:]) == m:
                ans = min(ans, z[0])
                ok = True
if ok:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

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





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



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

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
mat.sort(key=lambda x: -x[0])
total_cost = 0
t_m = [0]*m
for row in mat:
    total_cost += row[0]
    for i in range(m):
        t_m[i] += row[i+1]
if any(i < x for i in t_m):
    print(-1)
    exit()
    
for row in mat:
    c = False
    for i in range(m):
        new = t_m[i] - row[i+1]
        if new < x:
            c = True
            break
    if c is False:
        total_cost -= row[0]
        for i in range(m):
            t_m[i] -= row[i+1]

print(total_cost)

Submission status: Wrong Answer

Solution code:
n,m,x = [int(i) for i in input().split()]
bk = []
for _ in range(n):
   bk.append([int(i) for i in input().split()])
rp = 2**n +1
ans = 1000000
for i in range(rp):
   rikai = [0]*m
   mon = 0
   for j in range(n):
      if i>>j & 1:
         mon += bk[j][0]
         for k in range(m):
            rikai[k] += bk[j][k+1]
   flag = True
   for j in rikai: #この組み合わせでいいか
      if j < x:
         flag = False
         break
   if flag:
      ans = min(ans,mon)
if ans == 1000000:
   ans = -1
print(ans)

Submission status: Wrong Answer

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


def rec(i: int, rikai, res):
  
  #print(i, rikai, res)
  if i == N:
    return res+1000000
  
  use_rikai = [ rikai[j] - arr[i][j+1] for j in range(M) ]
  
  flag = True
  for r in use_rikai:
    if r <= 0: continue
    else: flag = False
  if flag:
    return res+arr[i][0]
  
  return min(rec(i+1, use_rikai, res+arr[i][0]), rec(i+1, rikai, res))

rikai = [X for j in range(M)]
res = rec(0, rikai, 0)
if res >= 1000000:
  print(-1)
else: print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,x = map(int,input().split())
l = []
for i in range(n):
    l.append(np.array(input().split(),dtype=int)) 
import itertools
num = [i for i in range(n)]
min = 1000000000000000000000000
k = 1
while k <n+1:
    a = list(itertools.combinations(num, k))
    for i in range(len(a)):
        total =np.zeros(m+1,dtype=int)
        for j in range(len(a[i])):
            total +=l[a[i][j]]
        if np.sum(np.where(total < x)[0]) <=0:
            if min > total[0]:
                min = total[0]
                k = n+2
    k +=1
if min == 1000000000000000000000000:
    print(-1)
else:
    print(min)

Submission status: Wrong Answer

Solution code:
import itertools
import sys

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

s = [i for i in range(n)]
t = []
list_num = []

for i in range(m):
  t.append(list(map(list, itertools.combinations(s, i + 1))))

for i in t:
  for j in i:
    k = [0] * (m + 1)
    for z in j:
      k = tuple(x + y for (x,y) in zip(k, num[z]))
    list_num.append(k)


list_num = list(sorted(list_num, key =lambda w : w[0]))
q = []

flag2 = 0

for i in list_num:
  flag = 1
  for j in range(1, len(i)):
    if(i[j] < x):
      flag = 0
      break
  if(flag == 1):
    q.append(i[0])
    flag2 = 1

if(flag2 == 1):
  print(min(q))
else: 
  print(-1)

Submission status: Wrong Answer

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

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

# print(A)

ans = float("inf")
for i in range(2 ** n):
    skill = [0] * (m+1)
    for j in range(n):
        if ((i >> j) & 1):
            for k in range(m):
                skill[k] += A[j][k]


    # print(ans, skill)

    if skill:
        for i in range(1, m):
            if x > skill[i]:
                break
        else:
            ans = min(ans, skill[0])

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m, x = [int(k) for k in input().split()]
c = np.zeros(n, dtype=int)
a = np.zeros((n, m), dtype=int)
rikai_a = np.zeros(m, dtype=int)
bool_c = np.full(n, True)
for i in range(n):
    c[i], *a[i] = [int(k) for k in input().split()]
money = 0
finish = 0
ave = np.zeros(n)
for i in range(n):
    ave[i] = np.average(np.array([(rikai_a[j] + a[i][j]) / x if rikai_a[j] + a[i][j] < x else 1 for j in range(m)])) / c[i]
for i in np.argsort(ave)[::-1]:
    for j in range(m):
        if rikai_a[j] < x:
            break
    else:
        break
    rikai_a[:] += a[i][0]
    money += c[i]
for i in range(m):
    if rikai_a[i] >= x:
        finish += 1
if finish == m:
    print(money)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

if __name__ == '__main__':
    T = input().split()
    N = int(T[0])
    M = int(T[1])
    X = int(T[2])
    price = np.zeros(N)
    qual = np.zeros((N, M))
    for n in range(N):
        t = input().split()
        price[n] = int(t[0])
        qual[n, :] = np.array([int(m) for m in t[1:]])

    ind = np.argsort(np.max(qual, axis=1) / price)[::-1]
    pay = 0
    sums = np.zeros(M)
    exit = 0
    for i in range(N):
        pay += price[ind[i]]
        sums += qual[ind[i], :]
        if np.all(sums >= X):
            print(int(pay))
            exit = 1
            break
    if exit == 0:
        print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,x = map(int,input().split())
l = []
for i in range(n):
    l.append(np.array(input().split(),dtype=int)) 
import itertools
num = [i for i in range(n)]
min = 100000000000000
k = 1
while k <n+1:
    a = list(itertools.combinations(num, k))
    for i in range(len(a)):
        total =np.zeros(m+1,dtype=int)
        for j in range(len(a[i])):
            total +=l[a[i][j]]
        if np.sum(np.where(total < x)[0]) <=0:
            if min > total[0]:
                min = total[0]
                k = n+2
    k +=1
if min == 100000000000000:
    print(-1)
else:
    print(min)

Submission status: Wrong Answer

Solution code:

#!/usr/bin/env python3

import sys
import pprint
import itertools

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	n, m, x = map(int, sys.stdin.readline().split())
	c = []
	a = []
	for i in range(n):
		ci, *ai = map(int, sys.stdin.readline().split())
		c.append(ci)
		a.append(ai)
	ans = 10**9
	log.print(a)
	for i in range(2**n):
		cost = 0
		rikai = [0]*m
		case = []
		for j in range(n):
			case.append(i>>j & 1)
		for j in range(n):
			if not case[j]:
				continue
			cost += c[j]
			for k in range(m):
				rikai[k] += a[j][k]
		# log.print(case, rikai, len(list(filter(lambda z:z>=x, rikai))))
		if len(list(filter(lambda z:z>=x, rikai))) == m:
			ans = min(cost, ans)
	if ans == 10**9:
		print(-1)
		exit()
	print(ans)





main()

Submission status: Wrong Answer

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])
if len(ans)==0:
    print(-1)
else:
    print(min(ans))

Submission status: Wrong Answer

Solution code:
import copy
def main():
  n,m,x=map(int,input().split())
  c=[[] for j in range(n)]
  a=[0]*m
  b=[0]*m
  for i in range(n):
    c[i]=list(map(int,input().split()))
  for k in range(1,m):
    b[k]=sum(map(lambda x: x[k], c))
    if b[k]<x:
      print(-1)
      exit()
  
  min_a0=sum(map(lambda x: x[0], c))
#print(a[0])
  b[0]=min_a0
  d=sorted(c,key=lambda x: x[0],reverse=True)
  a=copy.deepcopy(b)
  for y in range(n):
    a=copy.deepcopy(b)
    for p in range(y,n):
      for k in range(1,m):
    #print(p)
        a[k]-=d[p][k]
        if a[k]<x:
      #print(k)
          min_a0=min(a[0],min_a0)
          for q in range(k+1):
            a[q]+=d[p][q]
          break
      a[0]-=d[p][0]
  
  #print(a[0])
  print(min_a0)
main()