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:
def main():
  n,m,x=map(int,input().split())
  c=[[] for j in range(n)]
  a=[0]*m
  for i in range(n):
    c[i]=list(map(int,input().split()))
  for k in range(1,m):
    a[k]=sum(map(lambda x: x[k], c))
    if a[k]<x:
      print(-1)
      exit()
  min_a0=sum(map(lambda x: x[0], c))
#print(a[0])
  a[0]=min_a0
  d=sorted(c,key=lambda x: x[0],reverse=True)
  for p in range(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()

Submission status: Wrong Answer

Solution code:
def add_arr(a, acc):
    res = {'c': a['c'] + acc['c'], 'a': [0]*len(a['a'])}
    for i in range(len(a['a'])):
        res['a'][i] = a['a'][i] + acc['a'][i]
    return res

def understood(x, acc):
    return all([a >= x for a in acc['a']])

def solve(n, m, x, l, acc):
    if len(l) == 0:
        return -1

    elif understood(x, acc):
        return acc['c']

    else:
        res = [c for c in [solve(n, m, x, l[0:i] + l[i+1:len(l)], add_arr(l[i], acc)) for i in range(len(l))] if c >= 0]
        return min(res) if len(res) > 0 else -1

if __name__ == '__main__':
    n, m, x = [int(arg) for arg in input().split()]
    l = []
    for _ in range(n):
        c, *a = [int(arg) for arg in input().split()]
        l.append({'c': c, 'a': a})
    print(solve(n, m, x, l, {'c': 0, 'a': [0]*m}))

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
N,M,X = (int(x) for x in input().split())
S = []
C = []
l = []
ans = 10000000
for i in range(N):
  l.append(i)
for i in range(N):
  s = [int(x) for x in input().split()]
  S.append(s)
npS = np.array(S)
#print(npS)
for i in range(1,N):
  C =  list(itertools.combinations(l,i)) + C
#print(C)
for i in C:
  wa = np.zeros(M+1)
  #print("#",wa,S)
  for j in range(len(i)):
   # print(j,wa)
    wa = wa + S[i[j]]
  #print(i,wa)
  cnt = 0
  for k in range(1,len(wa)):
    if wa[k] >= X:
      cnt += 1
   # print(cnt,(ans > wa[0]))
    if cnt == M and ans > wa[0]:
      ans = wa[0]
if ans == 10000000:
  print(-1)
else:
  print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

N,M,X=map(int,input().split())
index=[i for i in range(N)]
flag = False
CA=[]
for i in range(N):
    CA.append([int(j) for j in input().split()])
CA=np.array(CA)
CAsum=np.sum(CA,axis=0)
if(np.size(np.where(CAsum[1:len(CAsum)]>=X))<M):
    print(-1)
else:
    for i in range(1,N):
        idx=list(itertools.combinations(index,i))
        for j in range(len(idx)):
            CAsum=np.sum(CA[idx[j],:],axis=0)       
            if(np.size(np.where(CAsum[1:len(CAsum)]>=X))==M):
                print(CAsum[0])
                flag = True
                break;
        if flag:
            break

Submission status: Wrong Answer

Solution code:
def resolve():
    from itertools import combinations
    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)

    min_cost = 100000
    for com in combinations(c, n):
        ans = [0] * m
        price = 0
        for i in com:
            p = i[1:]
            price += i[0]
            for n in range(len(ans)):
                ans[n] += p[n]

            if all([i >= x for i in ans]):
                if price < min_cost:
                    min_cost = price
                break
    if min_cost == 100000:
        print(-1)
    else:
        print(min_cost)

resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(N+1)]
ans=10**5
for i in range(N):
    A[i]=(list(map(int,input().split())))
A=np.array(A)
#print(A)
for i in range(2**N):
    B=np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            B+=A[j]
    #print(B)
    if ans>=B[0] and X<=np.amin(B[1:]):
        ans=B[0]
if ans==100000:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import heapq
import math
import operator as op
from collections import Counter
from functools import reduce

import numpy as np


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    N, M, X = get_inputs(int)
    Cs = np.empty(N, dtype=np.int)
    A_mat = np.empty((N, M), dtype=np.int)
    for i in range(N):
        CAs = get_inputs(int)
        Cs[i] = CAs[0]
        for j in range(M):
            A_mat[i, j] = CAs[j+1]

    if (np.sum(A_mat, axis=0) >= X).all():
        def dfs(i, As_cur, C_cur):
            # Buy Ci
            As_buy = As_cur + A_mat[i, :]
            C_buy = C_cur + Cs[i]
            if (As_buy >= X).all():
                # Accomplish
                return C_buy
            else:
                # Don't buy Ci
                if i < N-1:
                    return min(dfs(i+1, As_buy, C_buy), dfs(i+1, As_cur, C_cur))
                else:
                    return np.float("inf")

        ans = dfs(0, np.zeros(M, dtype=np.int), 0)
        assert ans != np.float("inf")
        print(ans)
    else:
        print(-1)

    # N, M, X = get_inputs()
    # CAs_arr = []
    # for _ in range(N):
    #     CAs = get_inputs(int)
    #     CAs_arr.append(CAs)

    # Sums = [0 for _ in range(M)]
    # for i in range(M):
    #     for j in range(N):
    #         Sums[i] += CAs_arr[j][i+1]

    # if all([Sum >= X for Sum in Sums]):
    #     pass
    # else:
    #     print(-1)


if __name__ == '__main__':
    main()

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)

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

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)

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())))
a.sort()
ans = [0 for i in range(m+1)]
money=1200001

for _ in range(n):
    for i in range(n):
        for j in range(m+1):
            ans[j] += a[i][j]
        if all([t >= x for t in ans[1:]]):
            if ans[0] < money:
                money = ans[0]
    add = a[0]
    a.remove(add)
    a.append(add)
    ans = [0 for i in range(m+1)]

if money != 1200001:
    print(money)
if money == 1200001:
    print(-1)

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-1):
        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:
import sys
import numpy as np
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

lst=[]
cnt=0
ans=100000000
for _ in range(n):
	a=list(map(int,readline().split()))
	lst.append(a)
	
for i in range(1,2 ** n):
    bag = []
    #print("pattern {}: ".format(i), end="")
    for j in range(n):
      if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行    		
      	bag.append(lst[j])  # フラグが立っていたら bag に果物を詰め
    #print(bag)
    cab=np.array(bag)
    sum=np.sum(cab,axis=0)
    
    cnt=0
    for k in range(m):
    	#print(sum[k+1])
    	if sum[k+1]>=x:
    		cnt+=1
    	if cnt==m:
    		ans=min(ans,sum[0])
    		
if min==100000000:
	print(-1)
else:
	print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
a=list(map(int,input().split()))
b=[]
def func(c):
  for i in  range(a[1]):
    if c[i+1]<a[2]:
      break
  else:
    return 1
  return 0
  
for i in range(a[0]):
  b.append(np.array(list(map(int,input().split()))))

c=b[0]
for i in range(1,a[0]):
  c=c+b[i]
if func(c)==0:
  print(-1)
else:
  i=(2**(a[0]+1))-2
  while i>=2**(a[0]):
    d=list(str(bin(i)))
    d=np.array(list(map(int,d[3:])))
    e=b[0]*d[0]
    for j in range(a[0]):
      e=e+(b[j]*d[j])
    if func(e) and c[0]>e[0]:
      c=e
    i-=1
  print(c[0])

Submission status: Wrong Answer

Solution code:
import itertools

N, M, X = list(map(int, input().split()))
C = []
A = []

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


for i in range(1, N+1):
    comb_list = list(itertools.combinations(range(N), i))
    flag_i = False
    min_cost = 10**7
    for comb in comb_list:
        know = [0] * M
        cost = 0
        for book in comb:

            for i in range(M):
                know[i] += A[book][i]
            cost += C[book]
        
        #達成チェック
        flag = True
        for i in range(M):
            if (know[i] < X):
                flag = False
              
        
        if (flag):
            flag_i = True
            
            if (min_cost > cost):
                min_cost = cost
    if (flag_i):
        print(min_cost)
        exit(0)

print(-1)

Submission status: Wrong Answer

Solution code:
B, A, R = map(int, input().split())

P = [list(map(int,input().split())) for i in range(B)]

V = 1000000

for i in range(1, 2 ** B):
	bag = []
	choniki = [0]*A
	for j in range(B):
		check = 0  
		if ((i >> j) & 1):  
			bag.append(P[j][0])
			for k in range (0, A):
				choniki[k]+=P[j][k+1]
			for l in range (0, A):
				if choniki[l] < R:
					check = 1
			if check == 0 and sum(bag) < V:
				V = sum(bag)

if V < 1000000:
	print(V)
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

num = [i for i in range(n)]

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


for k in range(2, n+1):
  correct = []

  for v in itertools.combinations(num, k):
    test = [] #組み合わせを作る
    for j in v:
      test.append(book_list[j])
      sum_test = np.sum(test, axis = 0) #組みあわせの合計
      cnt = 0
      for i in range(1, m+1):
        if sum_test[i] >= x:
          cnt += 1
      if cnt == m:
        correct.append(sum_test[0]) #正解を入れる
  if sum(correct) > 0:
    print(min(correct))
    exit()
print('-1')

Submission status: Wrong Answer

Solution code:
import itertools
n, m, x = map(int, input().split())
a_list = []
total = [0] * m
for i in range(n):
	targets = list(map(int, input().split()))
	a_list.append(targets)
r_list = []
for i, _ in enumerate(a_list, 1):     
	for j in itertools.combinations(a_list, r=i):
		targets = [0] * (m+1)
		for t in j:
			k = 0
			for target in t:
				targets[k] += target
				k += 1
		if min(targets) >= x:
			r_list.append(targets)
if len(r_list) == 0:
	print(-1)
else:
	r = sorted(r_list, key=lambda x: x[0])
	print(r[0][0])

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x=map(int,input().split())
lists=[]
zero=[0 for i in range(m+1)]
array=zero
ans=[]
for i in range(n):
    lists.append(list(map(int,input().split())))
for i in range(n+1):
    for pair in itertools.combinations(lists,i):
        for j in range(len(pair)):
            array=list(map(lambda x,y: x+y,array,list(pair[j])))
        for k in range(m):
            if array[k+1]<x:
                break
            else:
                ans.append(array[0])
        array=zero
print(min(ans) if ans else "-1")

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m, x = map(int, input().split())
c = []
nls = list()
for i in range(n):
    l = list(map(int, input().split()))
    c.append(l)

nls = np.array(c)
f=0
if not all(np.sum(nls, axis=0) >= x):
    f = 1
    print("-1")   
else:
    import itertools
    import pprint
    result=[]
    final =[]
    for n in range(1,len(c)+1):
        for conb in itertools.combinations(c, n):
            result.append(list(conb))
    for l in result:
        l=np.array(l)
        tmp = np.sum(l, axis=0)
        # print("tmp", tmp)
        if all(tmp >= x):
            final.append(tmp.tolist())
    final.sort()
    print(final[0][0])

Submission status: Wrong Answer

Solution code:
def solve():
    N, M, X = map(int, input().split()) 
    import numpy as np
    arr = np.ones((N,M+1), int) * 1e18
    for i in range(N):
        arr[i] = list(map(int, input().split()))
    
    arr = arr[np.argsort(arr[:, 0])[::-1]]
    C = arr[:, 0]
    arr = arr[:, 1:]
    # print(C)
    # print(arr)

    if any(np.sum(arr, axis=0) < X):
        return -1

    i = 0
    for _ in range(N):
        if any(np.sum(np.delete(arr, i, axis=0), axis=0) < X):
            i += 1
        else:
            arr = np.delete(arr, i, axis=0)
            C = np.delete(C, i)

    return int(C.sum())


if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
import itertools

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

Z = []
for i in range(N):
  Z.append(i)
  
for i in range(1, N+1, 1):
  comb = list(itertools.permutations(Z, i))
  cost = []
  for j in comb:
  	ca_list = []
  	ca_us = [0] * i
  	for k in range(len(j)):
  	  ca_list.append(CA[j[k]][1:(M+2)])
  	for k in range(len(j)):
  	  for l in range(i):
  	  	ca_us[l] += ca_list[k][l]
  	if min(ca_us) >= X:
  	  c = 0
  	  for k in range(i):
  	  	c += CA[j[k]][0]
  	  cost.append(c)
  if cost:
    print(min(cost))
    break
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
from itertools import chain, combinations

N, M, X = [int(n) for n in input().split()]

matrix = np.zeros((N,M+1))
for i in range(N):
    matrix[i] = np.array([int(n) for n in input().split()])

total = np.sum(matrix[:,1:],axis=0)
if not all(i >= X for i in total):
    print(-1)
    sys.exit(0)

def checkthresh(A, thresh):
    return all(i >= thresh for i in A)

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(1, len(s)+1))

cost = 10**5
for subset in powerset(range(N)):
    sum_subset = np.zeros((1,M+1))
    for i in subset:
        sum_subset += matrix[i,:]
    sum_subset = sum_subset[0]
    if checkthresh(sum_subset[1:], X):
        cost = min(cost, sum_subset[0])

print(int(cost))

Submission status: Wrong Answer

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]*6)
  else:
    for j in i:
      tmp = list(map(lambda a,b: a + b, tmp,j))
    sum.append(tmp)
    
min_price = 1000000
 
for i in sum:
  t = 0
  for j in i:
    if X > j:
      t = 1
  if t == 0:
    min_price = min(min_price, i[0])
 
if min_price == 1000000:
  print(-1)
else:
  print(min_price) 
#print(move_list)

Submission status: Wrong Answer

Solution code:
import itertools

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

ok = False
cur_price = (10 ** 5) * n + 1
for i in range(1, n + 1):
    answers = list(itertools.combinations(range(n), i))
    # print(answers)
    for ans_list in answers:
        sum_list = [0] * (m + 1)
        print(sum_list)
        for ans in ans_list:
            # print(all_list[int(ans[0])])
            sum_list = [a + b for a, b in zip(sum_list, all_list[int(ans)])]
        # print(sum_list)
        if min(sum_list[1:]) >= x:
            if sum_list[0] < cur_price:
                cur_price = sum_list[0]
                ok = True

if ok:
    print(cur_price)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n, m, x = map(int, input().split())
    ca = [list(map(int, input().split())) for i in range(n)]
    ans = float("inf")
    subsc = []  #選ばれている本
    if m == 1:
        print(-1 if x > ca[0][-1] else ca[0][-1])
        exit()
    for i in range(1 << n):
        for j in range(n):
            if (i >> j)&1:
                subsc.append(ca[j])
        flag = True
        cost = 0 #係る金額
        unst = 0 #各アルゴリズムの理解度
        if len(subsc) == 0:
            continue  
        for j in range(1,m):
            for k in range(len(subsc)):
                unst += subsc[k][j]
            if unst < x:
                flag = False #一つでもクリアできなければFalseになるはず
            unst = 0
        for j in range(len(subsc)):
            cost += subsc[j][0]
        if flag:
            ans = min(ans, cost)
        flag = True
        cost = 0
        subsc = []
    if ans == float("inf"):
        ans = -1
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================

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)

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

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**9
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**9):
    print(-1)
else:
    print(minimum)

Submission status: Wrong Answer

Solution code:
def python_list_add(in1, in2):
  for i in range(len(in1)):
    in1[i] = in1[i] + in2[i]
  return in1
  
n, m, x = map(int, input().split())
a = []
for i in range(n):
  a.append(list(map(int, input().split())))
ans = []
s = [0]*(m+1)
s = python_list_add(s, a[0])
for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    for i11 in range(2):
                      for i12 in range(2):
                        if i1 == 1 and n >= 1:
                          s = python_list_add(s, a[0])
                        if i2 == 1 and n >= 2:
                          s = python_list_add(s, a[1])
                        if i3 == 1 and n >= 3:
                          s = python_list_add(s, a[2])
                        if i4 == 1 and n >= 4:
                          s = python_list_add(s, a[3])
                        if i5 == 1 and n >= 5:
                          s = python_list_add(s, a[4])
                        if i6 == 1 and n >= 6:
                          s = python_list_add(s, a[5])
                        if i7 == 1 and n >= 7:
                          s = python_list_add(s, a[6])
                        if i8 == 1 and n >= 8:
                          s = python_list_add(s, a[7])
                        if i9 == 1 and n >= 9:
                          s = python_list_add(s, a[8])
                        if i10 == 1 and n >= 10:
                          s = python_list_add(s, a[9])
                        if i11 == 1 and n >= 11:
                          s = python_list_add(s, a[10])
                        if i12 == 1 and n >= 12:
                          s = python_list_add(s, a[11])
                        do = True
                        for j in s:
                          if j < x:
                            do = False
                            break
                          if do:
                            ans.append(s[0])
                        s = [0]*m
if len(ans) > 0:
  print(min(ans))
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
ca = []
for i in range(n):
    ca.append(list(map(int,input().split())))
ca.sort(key=lambda x:x[0]/sum(x))
algo = [0 for j in range(m)]
price = 0
for book in ca:
    flag = 0
    for num in range(m):
        algo[num] += book[num+1]
        if algo[num] >= x:
            flag += 1
    price += book[0]
    if flag == m:
        break
else:
    price = -1
#print(ca)
print(price)

Submission status: Wrong Answer

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

# 縦の合計
sums = [sum(CA[i][j] for i in range(N)) for j in range(M + 1)]

# print(CA)
# print(sums)

# 価格の高い順に並び替え
for ca in sorted(CA, key=lambda x: x[0], reverse=True):
    # print(ca)
    # X に達しないならスキップ
    if any(sums[j + 1] - ca[j + 1] < X for j in range(M)):
        continue

    sums[0] -= ca[0]
    for j in range(M):
        sums[j + 1] -= ca[j + 1]

print(-1 if any(sums[j + 1] < X for j in range(M)) else sums[0])

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
cost = []
weights = [[] for i in range(m)]
for i in range(n):
    a = [int(i) for i in input().split()]
    cost.append(a[0])
    for j in range(1,len(a)):
        weights[j-1].append(a[j])
import math
def min_cost(n,x,i,w):
    if i == n and w < x:
        return math.inf
    if w >= x :
        return 0
    else :
        return min(min_cost(n,x,i+1,w),cost[i]+min_cost(n,x,i+1,w+weight[i]))

ans = -1
for i in range(m):
    weight = weights[i]
    a = min_cost(n,x,0,0)
    ans = max(ans,a)
if math.isfinite(ans):
    print(ans)
else :
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
comb = []
for i in range(0, n+1):
    comb.append(list(itertools.combinations(c, i)))
ans = []
for i in range(len(comb)):
    for j in range(len(comb[i])):
        flag = True
        for l in range(1, m):
            sum = 0
            for k in range(len(comb[i][j])):
                sum += comb[i][j][k][l]
            if sum < x:
                flag = False
                break
        if flag:
            cos = 0
            for k in range(len(comb[i][j])):
                cos += comb[i][j][k][0]
            ans.append(cos)
if ans:
    print(min(ans))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def solve():
    N, M, X = map(int, input().split()) 
    import numpy as np
    arr = np.ones((N,M+1), int) * 1e18
    for i in range(N):
        arr[i] = list(map(int, input().split()))
    
    arr = arr[np.argsort(arr[:, 0])[::-1]]
    C = arr[:, 0]
    arr = arr[:, 1:]
    print(C)
    print(arr)

    if any(np.sum(arr, axis=0) < X):
        return -1

    i = 0
    for _ in range(N):
        if any(np.sum(np.delete(arr, i, axis=0), axis=0) < X):
            i += 1
        else:
            arr = np.delete(arr, i, axis=0)
            C = np.delete(C, i)

    return int(C.sum())


if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(N+1)]
ans=10**5
for i in range(N):
    A[i]=(list(map(int,input().split())))
A=np.array(A)
#print(A)
for i in range(2**N):
    B=np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            B+=A[j]
    #print(B)
    if ans>=B[0] and X<=np.amin(B[1:M+1]):
        ans=B[0]
if ans==100000:
    print(-1)
    exit()
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int, input().split())
import numpy as np
C=[]
A=np.array([[0]*m]*n)
for i in range(n):
    l = np.array(list(map(int, input().split())))
    C.append(l[0])
    A[i]+=np.array(l[1:])
D=sum(A[j] for j in range(n))
ans=[sum(C)]
L=[1]*n
def f(L, D, cost):
    global x
    indices=[i for i, y in enumerate(L) if y == 1]
    for i in indices:
        F=D-A[i]
        if min(F) >= x:
            ans.append(cost-C[i])
            L[i]=0
            f(L, F, cost-C[i])
f(L, D, sum(C))

if min(D) < x:
    print(-1)
else:
    print(min(ans))

Submission status: Wrong Answer

Solution code:
from functools import reduce
def judge(l):
    for i in l[1:]:
        if i < 0:
            return False
    else:
        return True
def is_remable(l, toberem):

    for i in range(0,len(l)):
        if l[i] < toberem[i]:
            return False
    return True

def rem(l,toberem):
    for i in range(0,len(l)):
        l[i] = l[i] - toberem[i]
    return l



def my_sum(l):
    ret = []
    for i in range(0, len(l[0])):
        temp = 0
        for j in l:
            temp += j[i]
        ret.append(temp)
    return ret
def rule(l):
    return l[0]

if __name__ == '__main__':
    n, m, x = tuple(map(int, input().split()))
    l = []
    for i in range(0, n):
        l.append(list(map(int, input().split())))
    l.sort(key=rule)
    total = my_sum(l)
    total = list(map(lambda a : a - x,total))
    total[0] = total[0] + x
    if judge(total)==False:
        print(-1)
    else:
        l.reverse()
        flag = True
        while flag == True:
            for i in range(0,len(l)):
                flag = False
                if is_remable(total, l[i]):
                    total = rem(total, l[i])
                    l.pop(i)
                    flag = True
                    break
        print(total[0])

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = [sum(j[1:])/a[k][0] for k,j in enumerate(a)]
c = sorted(b,reverse=True)
l = [0]*m
p = 0
for i in c:
    if all([i>=x for i in l]):
        break
    f = a[b.index(i)]
    p+=f[0]
    for k,j in enumerate(f[1:]):
        l[k]+=j
if all([i>=x for i in l]):
    print(p)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
fi = list(map(int,input().split()))
n = fi[0]
m = fi[1]
x = fi[2]
c = []
cn = []
y = 1
for k in range(n):
  cn.append(k)
for i in range(n):
  a = list(map(int,input().split()))
  c.append(a)
for j in range(m):
  wa = 0
  for s in range(n):
    wa=wa+c[s][j+1]
  if wa <= x:
    y=y*0

money = []
if not y==0:
  for s in range(n+1):
    ca = list(itertools.combinations(cn, s+1))
    cb = len(ca)
    for q in range(cb):
      cwa = []
      chan = 0
      for l in range(m+1):
        cwa.append(0)
      for p in range(s+1):
        cwa = list(map(lambda x,y: x+y, c[ca[q][p]], cwa))
      for t in range(m):
        if cwa[t+1]>=x:
          chan = chan+1
        if chan ==m:
          money.append(cwa[0])
  print(min(money))
else:
  print(-1)