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 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, m + 1):
    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:
import itertools 
def solve():
    n, m, x = map(int, input().split())
    c = []
    a = []
    for _ in range(n):
        C, *A = map(int, input().split())
        c.append(C)
        a.append(A)

    ans = n*1e5
    for i in range(n):
        for j in itertools.combinations(range(n), i+1):
            cnt = [0]*m
            for k in j:
                for l in range(m):
                    cnt[l] += a[k][l]
            for s in range(m):
                if cnt[s] < x:
                    break
                if s == m-1:
                    num = 0
                    for q in j:
                        num += c[q]
                    ans = min(ans, num)
    if ans == n*1e5:
        ans = -1
            
    return ans
    

print(solve())

Submission status: Wrong Answer

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

MOD = 10**9+7
a = [0]*M
value = [0]
ans = MOD

for i in range(2**N):
    for j in range(M+1):
        if(i >> j) & 1:
            for k in range(M):
                a[k] += A[j][k+1]
            value.append(A[j][0])

    if min(a) >= X :
        ans = min(ans,sum(value))
    a = [0]*M
    value = []

print(-1 if ans == MOD else ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

n,m,x=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
li=np.array(li)
y=np.sum(li, axis=0)
if(np.min(y[1:])<x):
    print(-1)

def check(i):
    a=list(itertools.combinations(range(n), i))
    
    ans=10000000000000
    for j in a:
        b=[0]*(m+1)
        for s in j:
            b+=li[s]
            
        #print(np.min(b[1:]))
        if(np.min(b[1:])>=x) and ans>b[0]:
            ans=b[0]
    return(ans)

for i in range(1,n+1):
    ans=check(i)
    if(ans>0 and ans!=10000000000000):
        print(ans)
        break

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product
import numpy as np
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M, X = map(int, readline().split())
    CA = list(list(map(int, readline().split())) for _ in range(N))
    CA = np.array(CA)
    target = [0] + [X]*M
    target = np.array(target)
    ans = INF
    for i in range(2**N):
        print(i)
        tmp = 0
        for j in range(N):
            if (i>>j)&1:
               tmp += CA[j]
        if np.all(tmp>=target):
            ans = min(ans, tmp[0])
    print(-1 if ans==INF else ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
i = 1
a = [[0 for i in range(m)] for j in range(n)]
c = [0 for i in range(n)]
while i <= n:
    li = list(map(int,input().split()))
    c[i-1] = li[0]
    a[i-1] = li[1:]
    i+=1

res_all = -1
for k in range(n):
    for l in range(k+1,n,1):
        aa = a[k:l+1]
        understandings = [0 for t in range(m)]
        for j in range(m):
            understanding = 0
            for i in range(l-k+1):
                understanding = understanding + aa[i][j]
            understandings[j] = understanding
        
        if all(elem >= 10 for elem in understandings):
            res = sum(c[k:l+1])
            if res_all == -1:
                res_all = res
            else:
                if 0 < res < res_all:
                    res_all = res

print(res_all)

Submission status: Wrong Answer

Solution code:
import numpy as np

def yn(t,x):
  for j in range(len(t)-1):
    if t[j+1] < x:
      return False
  return True
  

n,m,x=list(map(int,input().split()))
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
  
a=np.array(a)
a=a[np.argsort(a[:,0])]
t=np.sum(a,axis=0)

for i in range(1,n+1):
  if yn(t-a[-i],x):
    t = t-a[-i]

if not yn(t,x):
  print("-1")
else:
  print(t[0])

Submission status: Wrong Answer

Solution code:
import itertools

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

book=[]
skil=[0]*M
for i in range(N):
    line=list(map(int,input().split(' ')))
    book.append(line)
    skil=list(map(lambda x,y:x+y,skil,line[1:]))

min_p=1200000
for n in range(1,N+1):
    for conbo in itertools.combinations(book,n):
        conbo_book=[0]*(1+M)
        for b in list(conbo):
            conbo_book=list(map(lambda x,y:x+y,conbo_book,b))
        if len([m for m in conbo_book[1:] if m>=X])==M:
            if min_p>conbo_book[0]:
                min_p=conbo_book[0]

print(min_p) if min_p<1200000 else print("-1")

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A, C = [], []
for _ in range(N):
    tmp = input().split()
    C.append(int(tmp[0]))
    A.append([int(i) for i in tmp[1:]])
is_clear = False
min_cost = 10**10
for flg_number in range(2 ** N - 1):
    flgs = format(flg_number, '0'+str(N)+'b')
    thr = [X] * M
    cost = 0
    for i in range(N):
        if flgs[i] == '1':
            cost += C[i]
            for j in range(M):
                thr[j] -= A[i][j]
    is_all_clear = True
    for j in range(M):
        if thr[j] > 0:
            is_all_clear = False
            break
    if is_all_clear:
        is_clear = True
        if min_cost > cost:
            min_cost = cost
if is_clear:
    print(min_cost)
else:
    print(-1)

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):

  if i == N:
    return 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:
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for i in range(N)]

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

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

Submission status: Wrong Answer

Solution code:
import itertools

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

a = [[0] * (m) for i in range(n)]

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

min_score = 100000000
ok_flag = 1

for d in range(1, m+1):
    for v in itertools.permutations(a, d):
 
        ok_flag = 1
        cost = 0
        for m1 in range(1, d):
            score = 0
            for m2 in range(0, d):
                score += v[m2][m1]

            if score < x:
                ok_flag = 0
            
            if ok_flag == 1:
                for m3 in range(d):
                    cost += v[m3][0]
                if cost < min_score:
                    min_score = cost

if min_score == 100000000:
    print(-1)
else:
    print(min_score)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np


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

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

    C = np.array(C)
    Q = np.array(Q)
    ok = False

    NN = range(N)
    ans = np.sum(C)

    for j in range(1, N):
        for jj in list(itertools.combinations(NN, j)):
            tmp_value = C[list(jj)]
            tmp_score = Q[list(jj)]
            sum_ = tmp_score.sum(axis=0)
            finish_sum_ = len(list(filter(lambda x: x >= X, sum_)))

            if finish_sum_ == M:
                ans = min(ans, tmp_value.sum())
                ok = True

    if not ok:
        print(-1)
        return

    print(ans)


resolve()

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):
		su += a[i][j]/co[i]
	main.append([su,i])

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

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 sys 
input = sys.stdin.readline
def dp(start,algo,cost):
	if start>=n:
		return
	global ans
	if all([True if i>=x else False for i in algo ]):
		ans = min(ans, cost)

	for i in range(start,n):
		temp = list(algo)
		for j in range(1,m+1):
			temp[j-1] += arr[i][j]
		for k in range(start+1,n):
			dp(k, temp, cost+arr[i][0])

for tt in range(1):
	n,m,x = map(int,input().split())
	arr = []
	cost = [0]*m
	ans = float('inf')
	for i in range(n):
		l = list(map(int,input().split()))
		arr.append(l)
	dp(0,cost,0)
	if ans != float('inf'):
		print(ans)
	else:
		print(-1)

Submission status: Wrong Answer

Solution code:
import sys



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

a=[]

s=[0]*m

money=0

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

  money+=A[0]

  for j in range(1,m+1):
    s[j-1]+=A[j]

for i in range(m):
  if s[i]<x:
    print("-1")
    sys.exit()

buy=[0]*n

saitei=-1

for i in range(1,(2**n)+1): #全組み合わせ
  buy=[0]*n
  t=[0]*m
  money=0
  i1=i
  for j in range(n): #どれを買うか
    buy[j]=(i1)%2
    if i1==1:
      i1=0

    i1=int((i1)/2)
    if buy[j]==1:
      money+=a[j][0]
      for k in range(m): #買った本no達成度の総和
        t[k]+=a[j][k]
  #print(buy)
  #print(t)
  flag=True
  for r in range(m):
    if t[r]<x:
      flag=False
      break
  if flag==True:
    if saitei==-1 or saitei>money:
      saitei=money

print(saitei)

Submission status: Wrong Answer

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

flag=True
flag2=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: Wrong Answer

Solution code:
import itertools
n,m,x=map(int,input().split())
l=[tuple(map(int,input().split())) for _ in range(n)]
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:
import itertools

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

book=[]
skil=[0]*M
for i in range(N):
    line=list(map(int,input().split(' ')))
    book.append(line)
    skil=list(map(lambda x,y:x+y,skil,line[1:]))

min_p=1200000
for n in range(1,N+1):
    for conbo in itertools.combinations(book,n):
        conbo_book=[0]*(1+M)
        for b in list(conbo):
            conbo_book=list(map(lambda x,y:x+y,conbo_book,b))
        if len([m for m in conbo_book[1:] if m>=X])==M:
            print(conbo_book)
            if min_p>conbo_book[0]:
                min_p=conbo_book[0]

print(min_p) if min_p<1200000 else print("-1")

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
array2=[list(map(int,input().split())) for i in range(N)]
flag=0
for i in range(M):
	s=0
	for j in range(N):
		s=s+array2[j][i+1]
	if s<X:
		flag=1
		break                                                                                                                                                                                                                                                                         
if(flag==1):
	print('-1')

Submission status: Wrong Answer

Solution code:
import itertools
n, m, x = map(int, input().split())
a = [0] * n
arr = []
ans = 10000
for i in range(n):
    a[i] = list(map(int, input().split()))
for i in range(1, n+1):
    for j in itertools.combinations(range(n), i):
        b = [0] * m
        c = 0
        for k in list(j):
            for l in range(m):
                b[l] += a[k][l+1]
            c += a[k][0]
        if sum(y >= x for y in b) == m:
            ans = min(ans, c)
if ans == 10000:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque

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

_sum = 0
list_A = list()
for _ in range(N):
    A = list(map(int, input().split()))
    list_A.append(A)
    _sum += A[0]

list_all = deque()
for n in range(0, N+1):
    for conb in itertools.combinations(list_A, n):
        list_all.append(list(conb))

can = False
ans = _sum
for _ in range(len(list_all)):
    tmp = list_all[_]
    see = [0] * M
    var = 0
    for i in range(len(tmp)):
        see = list(map(sum, zip(see, tmp[i][1::M+1])))
        var += tmp[i][0]
    if all(elem >= X for elem in see): 
        ans = min(ans, var)
        can = True

if can:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

books.sort(key=lambda x: x[0])

combi_books = []
for n in range(1, N + 1):
    for c in itertools.combinations(books, n):
        combi_books.append(c)

mn = float('inf')
for books in combi_books:
    N = [0] * (M + 1)
    for b in books:
        N[0] += b[0]
        for n in range(1, M + 1):
            N[n] += b[n]
    for n in range(1, M + 1):
        if N[n] < X:
            break
        else:
            mn = min(mn, N[0])

print(mn) if mn != float('inf') else print(-1)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
mainlist=[]
ans=[]
sum=[]
money=[]
ans2=0
for i in range(n):
    list2=list(map(int,input().split()))
    mainlist.append(list2[1:])
    ans2+=list2[0]
    money.append(list2[0])
count=0
yn=0
for i in range(m):
    for j in range(n):
        count+=mainlist[j][i]
    if count<x:
        yn=1
        break
    sum.append(count)
    count=0
if yn==1:
    print(-1)
else:
    yn=0
    for i in range(m):
        sum[i]=sum[i]-x
    for i in range(n):
        for j in range(m):
            if sum[j]<mainlist[i][j]:
                yn=1
        if yn==0:
            ans.append(i)
            for k in range(m):
                sum[k]=sum[k]-mainlist[i][k]
    for i in range(len(ans)):
        ans2-=money[i]
    print(ans2)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

C = np.array([list(map(int, input().split())) for _ in range(N)])
# print(C)
sum_C = np.sum(C,axis=0)
# print(sum_C)

for num in sum_C:
    if num < X:
        print(-1)
        exit()

cost = float("inf")
for iii in [0, 1]:
    for ii in [0, 1]:
        for i in range(M+1):
            cc = sorted(C, key=lambda x:x[0], reverse=iii)
            ccc = np.array(sorted(cc, key=lambda x:x[i], reverse=ii))
            # print("ccc", ccc)
            sum_Ccopy = sum_C.copy()
            for j in range(N):
                sum_Ccopy -= ccc[j]
                # print("sum_Ccopy", sum_Ccopy)
                # print(np.all(sum_Ccopy[1:] >= X))
                # print(sum_Ccopy[0])
                if np.any(sum_Ccopy[1:] < X):
                    break
                    # print(sum_Ccopy[0])
                cost = min(cost, sum_Ccopy[0])
                # print(cost)
    
print(cost)

Submission status: Wrong Answer

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


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
#print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    clear = [l for l in bug if l >= X]
    #print(clear)
    if len(bug) == len(clear):
        ways.append(bug[0])

    bug = []
    for k in range(M + 1):
        bug.append(0)

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

Submission status: Wrong Answer

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

a = [[0 for j in range(m)] for i in range(n)]
c = [0] * n

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

for i in range(m):
    s = 0
    for j in range(n):
        s += a[j][i]
    if s < x:
        print(-1)
        exit()

s = 1000000

for i in range(1, n+1):
    for j in list(combinations(range(n), i)):
        t = [0] * m
        S = 0
        for k in range(len(j)):
            S += c[j[k]]
            for l in range(m):
                t[l] += a[j[k]][l]
        p = s
        s = min(s, S)
        for y in range(m):
            if t[y] < x:
                s = p
                break
print(s)

Submission status: Wrong Answer

Solution code:
s = input().split();
n = int(s[0]);
m = int(s[1]);
x = int(s[2]);
r = [];
r.append(x);
min = 0;
i = 0;
cnt = 0;
flag = True;
import sys;
for i in range(m):
    r.append(0);

while(n > 0 and flag):
    nums = list(map(int,input().split()));
    min += nums[0];
    i = 1;
    cnt = 0;
    while(i < len(nums)):
        r[i] += nums[i];
        if(r[i] >= x):
            cnt += 1;
        if(cnt == len(r) - 1):
            flag = False;
        i += 1;
    n -= 1;

if(flag == False):
    print(min);
else:
    print(-1);

Submission status: Wrong Answer

Solution code:
import itertools
N, M, X = map(int, input().split())
book_lists = [list(map(int, input().split())) for i in range(N)]
no_skill_flg = True
for i in range(1, N+1):
    for j in itertools.combinations(book_lists,i):
        sum_list = [0 for _ in range(M+1)]
        for book_date in j:
            for k, l in enumerate(book_date):
                sum_list[k] += l
        print(sum_list)
        if all([s >= X for s in sum_list[1:]]):
            no_skill_flg = False
            if 'ans' in globals():
                ans = min(ans, sum_list[0])
            else:
                ans = sum_list[0]
print(ans if not no_skill_flg else -1)

Submission status: Wrong Answer

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

MOD = 10**9+7
a = [0]*M
value = [0]
ans = MOD

for i in range(2**N):
    if min(a) >= X :
        ans = min(ans,sum(value))
    a = [0]*M
    value = []
    for j in range(M+1):
        if(i >> j) & 1:
            for k in range(M):
                a[k] += A[j][k+1]
            value.append(A[j][0])
print(-1 if ans == MOD else ans)

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 += 12000000
	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:
n ,m, x = map(int, input().split())

book = [list(map(int, input().split())) for _ in range(0, n)]

money=[]
skill1=[]
skill2=[]
skill3=[]
skill4=[]
skill5=[]
skill6=[]
skill7=[]
skill8=[]
skill9=[]
skill10=[]
skill11=[]
skill12=[]



for i in range(0, m+1):
    for j in range(0, n):
        if i == 0:
            try:
                money.append(book[j][i])
            except IndexError:
                continue
            
        elif i % 12 == 1:
            skill1.append(book[j][i])
        elif i % 12 == 2:
            skill2.append(book[j][i])
        elif i % 12 == 3:
            skill3.append(book[j][i])
        elif i % 12 == 4:
            skill4.append(book[j][i])
        elif i % 12 == 5:
            skill5.append(book[j][i])
        elif i % 12 == 6:
            skill6.append(book[j][i])
        elif i % 12 == 7:
            skill7.append(book[j][i])
        elif i % 12 == 8:
            skill8.append(book[j][i])
        elif i % 12 == 9:
            skill9.append(book[j][i])
        elif i % 12 == 10:
            skill10.append(book[j][i])
        elif i % 12 == 11:
            skill11.append(book[j][i])
        elif i % 12 == 0:
            skill12.append(book[j][i])
all_skill = [skill1]+[skill2]+[skill3]+[skill4]+[skill5]+[skill6]+[skill7]+[skill8]+[skill9]+[skill10]+[skill11]+[skill12]
flag=True
for i in all_skill:
    if len(i)==0:
        break;
    elif sum(i)<x:
        flag=False

if flag:
    print(sum(money))
else:
    print('-1')

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())

for i in cost:
  heapq.heappush(ans,i)
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:
import numpy as np
N, M, X = map(int, input().split())
C = []
for _ in range(N):
    C.append(list(map(int, input().split())))
C_np = np.array(C)
# 全部足しても目標に達成しない場合-1
for i in np.sum(C_np, axis=0)[1:]:
    if i < X:
        print(-1)
        break
# 未完成
else:
    for i in C_np:
        pass

Submission status: Wrong Answer

Solution code:
def main():
    n,m,x = map(int, input().split())
    c = [list(map(int, input().split())) for _ in range(n)]
    c = sorted(c, key=lambda x:sum(x[1:])/x[0], reverse=True)
    ans = 0
    rikaido = [0]*m
    possible = False
    for i in c:
        if min(rikaido) >= x:
            possible = True
            break
        ans += i[0]
        for num, val in enumerate(i[1:]):
            rikaido[num] += val
    print(ans) if possible else print(-1)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    clear = [l for l in bug if l >= X]
    print(clear)
    if len(bug) == len(clear):
        ways.append(bug[0])

    bug = []
    for k in range(M + 1):
        bug.append(0)

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

Submission status: Wrong Answer

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

C = []
A = [[] for _ in range(M)]
for i in range(N):
    arr = list(map(int, input().split()))
    C.append(arr[0])
    for j in range(M):
        A[j].append(arr[j+1])

count = 0
for i in range(M):
    if X <= sum(A[i]):
        count += 1

ans = [sum(A[i]) for i in range(M)]
ans_flag = [False for _ in range(M)]
cost = sum(C)
if count != M:
    print('-1')
else:
    for _ in range(M):
        idx = C.index(max(C))
        baf = C[idx]
        for i in range(M):
            ans[i] -= A[i][idx]
            if ans[i] < X:
                ans_flag[i] = True
            del A[i][idx]
        
        cost -= C[idx]
        del C[idx]

        if (sum(ans_flag) > 0):
            break

    print(cost+baf)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
N,M,X =map(int,input().split())
A =[]

ans = int(1e12)
for i in range(N):
  c,*a = map(int,input().split())
  A.append([c,np.array(a)])

for k in range(M+1):
  for i in list(itertools.combinations(A, k)):
    tmp_s = np.array([0 for l in range(M)])
    tmp_c = 0
    for j in i:
      tmp_s += j[1]
      tmp_c += j[0]
    if tmp_c < ans and (tmp_s >=X).all():
      ans = tmp_c
    
print(ans if ans<1e12 else -1)

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(i,n):
        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:
N,M,X = map(int,input().split())
Datas=[]
Ms = [0]*M
flag=True
amount=0
for n in range(N):
  temp=list(map(int, input().split()))
  for i in range(M):
    Ms[i]+=temp[i+1]
  Datas.append(temp)
  amount+=temp[0]
for i in range(M):
  if Ms[i] < X:
    flag=False
if flag:
  print(amount)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
N, M, X = (int(i) for i in input().split())
Y = np.zeros((N, M+1))
for i in range(N):
    Y[i,:] = [int(i) for i in input().split()]
C = Y[:,0]
A = np.matrix(Y[:,1:])
res = np.inf
f = '0'+str(N)+'b'
for i in range(2**N):
    z = np.array([int(s) for s in list(format(i, f))])
    cost = z @ C
    skill = z * A
    if (skill >= X).all() and (cost < res):
        res = cost
if np.isinf(res):
    print(-1)
else:
    print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
N, M, X = map(int, input().split())
A = []
for i in range(N):
    A.append([i for i in map(int, input().split())])
A = np.array(A)
sum_A = A.sum(axis=0)
if not all(sum_A[1:] > X):
    print("-1")
else:
    l1=[0, 1]
    min_val = A.sum(axis=0)[0]
#print('m', min_val)
    for v in itertools.product(l1, repeat=N):
        if sum(list(v)) == 0:
            continue
        v = np.array(v)
        if all(A[v==1].sum(axis=0)[1:] >= X):
            if min_val > A[v==1].sum(axis=0)[0]:
                #print(A[v==1].sum(axis=0)[0])
                min_val = A[v==1].sum(axis=0)[0]
    print(min_val)

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(reverse=True)
lis=np.array(l)
total= np.sum(l,axis=0)
for i in range(1,m+1):
  if total[i] < x:
    print(-1)
    exit()
    
for i in range(n):
  for j in range(1,m+1):
    if total[j]-l[i][j]>= x:
      if j==m:
        for k in range(0,m+1):
          total[k]-=l[i][k]
      else:
        continue
    else:
      break
print(total[0])