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:
N, M, X = map(int,input().split())

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

for i in range(2 ** N):
  s = 0
  am = []

  for j in range(N):  # このループが一番のポイント
      if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
        am.append(CAM[j])

  j = False
  sss = [0] * (M+1)
  for kk in range(len(am)):
    s += am[kk][0]
    for m in range(0, M):
      sss[m+1] += am[kk][m+1]
  
  if len([i for i in sss[1:] if i >= X] ) == len(sss[1:]):
    b = True
    minn = min(s,minn)
  
  print(sss)
  # if x >= X and y >= X and z >= X:
  #   minn = min(s,minn)
  #   b = True

print(minn if b == True else -1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import itertools
import sys

N, M, X  = map(int, input().split())
money = []
A = []
ans = []
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)

    
def run(lis, num, A, X, M, ans):
    ans_list = []
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if count == M:
            ans_list.append(sum(list(team)))
    if not len(ans_list) == 0:
        ans.append(min(ans_list))
    
    return ans
        
for i in range(2, N+1):
    ans = run(money, i, A, X, M, ans)
    
if not len(ans) == 0:
    print(min(ans))
    
else:
    print(-1)

Submission status: Wrong Answer

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

###
# main
if(__name__ == '__main__'):
    # input
    n, m, x = map(int, input().split(" "))

    book = []
    c_sum = 0
    sum_li = [0 for _ in range(m)]
    for i in range(n):
        b = list(map(int, input().split(" ")))
        book.append(b)
        c = b[0]
        c_sum += c
        for al in range(m):
            a = b[al+1]
            sum_li[al] += a

    ans = -1
    for al in range(m):
        if sum_li[al] < x:
            break
    else:
        q = []
        cost_list = [c_sum]
        init_list = [c_sum]
        for al in range(m):
            init_list.append(sum_li[al])
        q.append(init_list)

        for i in range(n):
            for tgt in q:
                cost = tgt[0] - book[i][0]
                tgt_list = [cost]
                for al in range(m):
                    cp = tgt[al+1] - book[i][al+1]
                    if cp < x:
                        break
                    else:
                        tgt_list.append(cp)
                else:
                    cost_list.append(cost)
                    q.append(tgt_list)

        cost_list.sort()
        ans = cost_list[0]

    print(ans)

# else:
    # do nothing

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
bag = {}
for i in range(n):
    bag[i]=list(map(int, input().split()))

min_ = 10**10
for bit in range(1<<n):
    understanding = [0 for j in range(m)]
    c = 0
    for i in range(n):
        if bit & (1<<i):
            for k in range(m):
                understanding[k] += bag[i][k+1]
            c += bag[i][0]
            
    if all([a >= x for a in understanding] ):
        min_ = min(min_, c)
if min_ == 10*10:
    min_ = -1
print(min_)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import itertools
import sys

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

for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)

    
def run(lis, num, A, X, M):
    ans_list = []
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if count == M:
            ans_list.append(sum(list(team)))
    if not len(ans_list) == 0:
        print(min(ans_list))
        sys.exit()
        
for i in range(1, N+1):
    run(money, i, A, X, M)

print(-1)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
bag = {}
for i in range(n):
    bag[i]=list(map(int, input().split()))

min_ = 10**10
for bit in range(1<<n):
    understanding = [0]*m
    c = 0
    for i in range(n):
        if bit & (1<<i):
            for k in range(m):
                understanding[k] += bag[i][k+1]
            c += bag[i][0]
            
    if all([a >= x for a in understanding] ):
        min_ = min(min_, c)
if min_ == 10*10:
    min_ = -1
print(min_)

Submission status: Wrong Answer

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

c_list = []
a_matrix = []

for i in range(n):
    items = list(map(int, input().split()))
    c_list.append(items[0])
    a_matrix.append(items[1:])

min_cost = 1000000 * (n+1)

for i in range(2^n):
    cost = 0
    skill_sum = [0 for _ in range(m)]
    bit_pattern = format(i, '0' + str(n) + 'b')[::-1]
    for i, a_line in enumerate(a_matrix):
        if bit_pattern[i] == "1":
            cost += c_list[i]
            for j, a in enumerate(a_line):
                skill_sum[j] += a
    
    if all(map(lambda skill_s: skill_s >= x, skill_sum)) and cost < min_cost:
        min_cost = cost

if min_cost >= 1000000 * (n+1):
    print(-1)
else:
    print(min_cost)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
cost = 0
flag = 0
min = 10000000000000000000000

for i in range(1<<n):
  r = [0]*m
  flag = 0
  cost = 0
  for j in range(n):
    if(i>>j&1):
      cost += a[j][0]
      for k in range(m):
        r[k] += a[j][k+1]
  for k in range(m):
    if(r[k] < x):
      flag = 1
      break
  if(flag == 0 and min > cost):
    min = cost
print(min)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
dp = [[[130000000 for i in range(x+1)]for j in range(m)]for k in range(n)]
a0 = list(map(int,input().split()))
for j in range(m):
    for k in range(x+1):
        if k <= a0[j+1]:
          dp[0][j][k] = a0[0]
        dp[0][j][0] = 0
for i in range(1,n):
    a = list(map(int,input().split()))
    for j in range(m):
        dp[i][j][0] = 0
        for k in range(x+1):
             dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j][max(k-a[j+1],0)]+a[0])

ans = 10000000000000
max = 0
for i in range(m):
    if dp[n-1][i][x] != 130000000 and dp[n-1][i][x] > max:
        max = dp[n-1][i][x]
    if dp[n-1][i][x] == 130000000:
        ans = -1
ans = min(ans,max)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
cost = 0
flag = 0
min = 10000000000000

for i in range(1<<n):
  r = [0]*m
  flag = 0
  cost = 0
  for j in range(n):
    if(i>>j&1):
      cost += a[j][0]
      for k in range(m):
        r[k] += a[j][k+1]
  for k in range(m):
    if(r[k] < x):
      flag = 1
      break
  if(flag == 0 and min > cost):
    min = cost
print(min)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

for n in range(1,2**N):
    a = str(bin(n))[2:]
    b = N-len(a)
    c = np.array(list('0'*b+a)).astype('bool')
    #print(c)
    check = ALL[c].sum(axis=0)
   
    if (check[1:] < X).sum() < 1:
      if  p >  check[0]:
        p = check[0]

if p == 120001:
  p = -1
  
print(int(p))

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = np.array(l)
ans = np.sum(l, 0)[0]
# ans_s = np.sum(l, 0)
count = 0
# if np.any(ans_s[1:] < x):
#     print(-1)
#     exit()
for i in range(1, n + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
            count += 1
print(int(ans) if count != 0 else -1)

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product

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

    cost_min = 1e18
    for idx in product([0, 1], repeat=N):
        cost = 0
        t = X * np.ones(M)
        for j in range(N):
            if idx[j] == 1:
                t -= qual[j, :]
                cost += price[j]
        if max(t) <= 0:
            if cost < cost_min:
                cost_min = cost
    if cost_min == 1e09:
        print(-1)
    else:
        print(int(cost_min))

Submission status: Wrong Answer

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

c_list = []
a_matrix = []

for i in range(n):
    items = list(map(int, input().split()))
    c_list.append(items[0])
    a_matrix.append(items[1:])

min_cost = 100000 * (n+1)

for i in range(128):
    cost = 0
    skill_sum = [0 for _ in range(m)]
    bit_pattern = format(i, '0' + str(n) + 'b')[::-1]
    for i, a_line in enumerate(a_matrix):
        if bit_pattern[i] == "1":
            cost += c_list[i]
            for j, a in enumerate(a_line):
                skill_sum[j] += a
    
    if all(map(lambda skill_s: skill_s >= x, skill_sum)) and cost < min_cost:
        min_cost = cost

if min_cost == 100000 * (n+1):
    print(-1)
else:
    print(min_cost)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int,input().split(' '))
a = [[] for i in range(n)]
e = [0] * m
sc = [0] * m
for i in range(n):
    l = list(map(int, input().split(' ')))
    sm = sum(l[1:])
    if sm == 0:
        sm = 1
        l[0] = 100000
    l.append(l[0] / sm)
    a[i] = l
a.sort(key = lambda v : v[-1:])
p = 0
for i in a:
    p += i[0]
    for j in range(m):
        e[j] += i[j + 1]
        sc[j] = 1 if e[j] >= x else 0
    if sum(sc) == m:
        break
        
    
r = p if sum(sc) == m else -1
print(r)

Submission status: Wrong Answer

Solution code:
def resolve():
	n, m, x = map(int, input().split())
	books = [list(map(int, input().split())) for _ in range(n)]

	pay = float('inf')
	for i in range(1 << n):
		selected = []
		for j in range(n):
			if i >> j & 1:
				selected.append(j)
		rem = [0] * m
		tmp_pay = 0
		for j in selected:
			tmp_pay += books[j][0]
			done = True
			for k in range(1, m):
				rem[k-1] += books[j][k]
				if rem[k-1] < x:
					done = False
			if done:
				pay = min(pay, tmp_pay)
	if pay == float('inf'):
		print(-1)
	else:
		print(pay)
resolve()

Submission status: Wrong Answer

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

c_list = []
a_matrix = []

for i in range(n):
    items = list(map(int, input().split()))
    c_list.append(items[0])
    a_matrix.append(items[1:])

min_cost = 100000 * (n+1)

for i in range(128):
    cost = 0
    skill_sum = [0 for _ in range(m)]
    bit_pattern = format(i, '0' + str(n) + 'b')[::-1]
    for i, a_line in enumerate(a_matrix):
        if bit_pattern[i] == "1":
            cost += c_list[i]
            for j, a in enumerate(a_line):
                skill_sum[j] += a
    
    if all(map(lambda skill_s: skill_s >= x, skill_sum)) and cost < min_cost:
        min_cost = cost

if min_cost == 100000 * (n+1):
    print("-1")
else:
    print(min_cost)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque
import numpy as np

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

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

can = False
ans = _sum
for i in range(2**N):
    var = 0
    see = np.array([0] * M)
    for j in range(N):
        if((i >> j) & 1):
            see += list_A[j][1::M+1]
            var += list_A[j][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:
# coding: utf-8
# Your code here!
import itertools
import sys

N, M, X  = map(int, input().split())
money = []
A = []
ans = 0
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
    
def run(lis, num, A, X, M):
    ans_list = []
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if count == M:
            ans_list.append(sum(list(team)))
    if not len(ans_list) == 0:
        print(min(ans_list))
        sys.exit()
        
for i in range(1, N+1):
    run(money, i, A, X, M)

print(-1)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int, input().split())
c =[list(map(int, input().split())) for i in range(n)]
ch = [0 for i in range(m+1)]
ans = 10000000000
for j in range(0,n):
    ch = [x+y for (x,y) in zip(ch,c[j])]
for j in range(1,m+1):
    if ch[j] < x:
        print(-1)
        break
a,all = [],[]
for i in range(1,n+1):
    a.append(i)
for i in range(1,2**len(a)):
    b = []
    for j in range(len(a)):
        if (i >> j) &1 == 1:
            b.append(a[j])
    all.append(b)
for i in range(len(all)):
    ch = [0 for i in range(m+1)]
    for j in range(len(all[i])):
        k = all[i][j]-1
        ch = [x+y for (x,y) in zip(ch,c[k])]
    t = 0
    for j in range(1,m+1):
        if ch[j] < x:
            t = 1
    if t == 0 and ans > ch[0]:
        ans = ch[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = np.array(l)
ans = np.sum(l, 0)[0]
ans_s = np.sum(l, 0)
count = 0
# if np.any(ans_s[1:] < x):
#     print(-1)
#     exit()
for i in range(1, m + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
            count += 1
print(int(ans) if count != 0 else -1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

cost =12*10**5+1
for n in range(2**N):
    a = str(bin(n))[2:]
    b = N-len(a)
    c = np.array(list('0'*b+a)).astype('bool')
    #print(c)
    ALL2 = ALL[1:]
    check = ALL2[c].sum(axis=0)
   
    if (check[1:] < X).sum() < 1:
      if  cost >  check[0]:
        cost = check[0]


if cost == 12*10**5+1:
  cost = -1
print(cost) 

print(ALL)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
dp = [[[13000000 for i in range(x+1)]for j in range(m)]for k in range(n+1)]
a0 = list(map(int,input().split()))
for j in range(m):
    for k in range(x+1):
        if k <= a0[j+1]:
          dp[0][j][k] = a0[0]
        dp[0][j][0] = 0
for i in range(1,n):
    a = list(map(int,input().split()))
    for j in range(m):
        dp[i][j][0] = 0
        for k in range(x+1):
             dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j][max(k-a[j+1],0)]+a[0])

ans = 10000000000000
max = 0
for i in range(m):
    if dp[n-1][i][x] != 13000000 and dp[n-1][i][x] > max:
        max = dp[n-1][i][x]
    if dp[n-1][i][x] == 13000000:
        ans = -1
ans = min(ans,max)

print(ans)

Submission status: Wrong Answer

Solution code:
prog = list(map(int, input().split()))
book = {}
points = [0] * prog[1]
answer = 0

for i in range(prog[0]):
    book[i] = list(map(int, input().split()))

sorted_book = dict(sorted(book.items(), key=lambda x:sum(x[1][1::]), reverse = True))
for j,k in sorted_book.items():
    if sum(points) > prog[1]*prog[2]:
        print(answer)
        break
    answer += k[0]
  
    for l in range(prog[1]):
        points[l] += k[l+1]

if sum(points) < prog[1]*prog[2]:
    print(-1)

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
A=[0]*(N)
for i in range(N):
  A[i]=[int(x) for x in input().split()]
def nap(p,q):
  if q==N:
    if min(p[1:M+1])>=X:
      lity[-1]=min(lity[-1],p[0])
    return
  nap(p,q+1)
  for i in range(M+1):
    p[i]=p[i]+A[q][i]
  nap(p,q+1)
lity=[]
lity.append(10**9)
r=[0]*(M+1)
nap(r,0)
if lity[-1]==10**9:
  print(-1)
else:
  print(lity[-1])

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
dp = [[[1300000 for i in range(x+1)]for j in range(m)]for k in range(n+1)]
a0 = list(map(int,input().split()))
for j in range(m):
    for k in range(x+1):
        if k <= a0[j+1]:
          dp[0][j][k] = a0[0]
        dp[0][j][0] = 0
for i in range(1,n):
    a = list(map(int,input().split()))
    for j in range(m):
        dp[i][j][0] = 0
        for k in range(x+1):
             dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j][max(k-a[j+1],0)]+a[0])


ans = 10000000000
max = 0
for i in range(m):
    if dp[n-1][i][x] != 1300000 and dp[n-1][i][x] > max:
        max = dp[n-1][i][x]
    if dp[n-1][i][x] == 1300000:
        ans = -1
ans = min(ans,max)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import itertools
import sys
import copy
N, M, X  = map(int, input().split())
money = []
A = []
ans = 0
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
    
def run(lis, num, A, X, M):
    ans_list = []
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if count == M:
            ans_list.append(sum(list(team)))
    if not len(ans_list) == 0:
        print(min(ans_list))
        sys.exit()
for i in range(1, N+1):
    run(money, i, A, X, M)

print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
N,M,X=map(int, input().split())
book = []
for _ in range(N):
    book.append(list(map(int, input().split())))
book = np.array(book)
money=pow(10,7)
for i in itertools.product([0,1], repeat=N):
    book2=book
    dellist = []
    for n,l in enumerate(i):
        if l==0:
            dellist.append(n)
    book2=np.delete(book2, dellist, 0)
    ansar = np.sum(book2,axis=0)
    if np.sum(ansar[1:]>=X)==M:
        if money>ansar[0]:
            money = ansar[0]
if money == pow(10,6):
    print(-1)
else:
    print(money)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import itertools
import sys
import copy
N, M, X  = map(int, input().split())
money = []
A = []
ans = 0
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
    
def run(lis, num, A, X, M):
    ans_list = []
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if count == M:
            ans_list.append(sum(list(team)))
    if not len(ans_list) == 0:
        print(min(ans_list))
        sys.exit()
for i in range(1, N+1):
    run(money, i, A, X, M)
    print(i)

print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
N,M,X = map(int,input().split())
A = [0]*M
C = []
Z = []
cz = []
b = 0
for i in range(N) :
    C.append(list(map(int,input().split())))

for i in range(1,N+1) :
    c = list(itertools.combinations(C,i))
    for j in range(len(c)) :
        A=[0]*M
        cj = c[j]
        for k in range(i) :
            ck = cj[k]
            for l in range(M) :
                A[l]+= ck[l]        
        for m in range(1,M) :
            if A[m] < X :
                break
            cz.append(A[0])

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

Submission status: Wrong Answer

Solution code:
import itertools
N,M,X = map(int,input().split())
A = [0]*M
C = []
Z = []
cz = []
b = 0
for i in range(N) :
    C.append(list(map(int,input().split())))

for i in range(1,N+1) :
    c = list(itertools.combinations(C,i))
    print(c)
    for j in range(len(c)) :
        A=[0]*M
        cj = c[j]
        for k in range(i) :
            ck = cj[k]
            for l in range(M) :
                A[l]+= ck[l]        
        for m in range(1,M) :
            if A[m] < X :
                break
            cz.append(A[0])

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

Submission status: Wrong Answer

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

ans = 1000000000
for k in range(2**N):
  price = 0
  rikaido=[0]*M
  for l in range(N):
    if k>>l & 1:
      #if CAAA[m][1] < price:
      price += int(CAAA[l][0])
      for t in range(M):
        rikaido[t] += int(CAAA[l][t])
        for r in rikaido:
          if r < X:
            break
        else:
          ans = min(ans, price)
if ans == 1000000000:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
import itertools



def resolve():
    N,M,X=pin()
    full=[0]*(M)
    cost=[0]*N
    books=[]
    for i in range(N):
        x,*y=pin()
        print(x,list(y))
        cost[i]=x
        books.append(list(y))
        for j in range(M):
            full[j]+=y[j]
    fmoney=sum(cost)
    amari=[f-X for f in full]
    print(fmoney,full,amari,books)
    ans=fmoney
    def search(currentmoney,bookset,currentamari):
        global ans
        for ic in  currentamari:
            if ic == 0 :return
        ans=min(ans,fmoney)
        for b in bookset:
            tempset=bookset
            tempset.discard(b)
            tempamari=[0]*M
            for ib in range(M):
                tempamari[ib]=currentamari[ib]-books[b][ib]
            print(tempset)
            search(currentmoney-cost[b],tempset,tempamari)
    search(fmoney,set(range(N)),amari)
    print(ans)
    
        
#%%submit!
#resolve()

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = np.array(l)
ans = np.sum(l, 0)[0]
ans_s = np.sum(l, 0)
if np.any(ans_s[1:] < x):
    print(-1)
    exit()
for i in range(1, m + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

A  = ALL.sum(axis=0)
cost =12*10**5+1
#ALL = np.sort(ALL, axis=0)

for n in range(2**N):
    a = str(bin(n))[2:]
    b = N-len(a)
    c = np.array(list('0'*b+a)).astype('bool')
    #print(c)
    ALL2 = ALL[1:]
    check = ALL2[c].sum(axis=0)
   
    if (check[1:] < X).sum() < 1:
      if  cost >  check[0]:
        cost = check[0]


if cost == 2**100:
  cost = -1
print(cost)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import itertools
import sys
import copy
N, M, X  = map(int, input().split())
money = []
A = []
ans = 0
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
    
def run(lis, num, A, X, M):
    ans_list =[]
    ans = sum(lis)
    tmp_ans = sum(lis)
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if count == M:
            ans_list.append(sum(list(team)))
    if not len(ans_list) == 0:
        print(min(ans_list))
        sys.exit()
for i in range(1, N):
    run(money, i, A, X, M)

print(-1)

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 cmb in list(itertools.combinations(A, k)):
    tmp_s = np.array([0 for l in range(M)])
    tmp_c = 0
    for j in cmb:
      tmp_s += j[1]
      tmp_c += j[0]
    F = True
    if tmp_c < ans:
      for j in range(M):
        if tmp_s[j] <X:
          F = False
      if F:
        ans = tmp_c

print(ans if ans < int(1e12) else -1)

Submission status: Wrong Answer

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

row_list = []
C_list = []
for _ in range(N):
  row = list(map(int, input().split()))
  row = np.array(row)
  C_list.append(row[0])
  row_list.append(row[1:])

  
def check(subset, C_list, row_list, X):
  if len(subset) == 0:
    return 0, False
  
  cost_list = [C_list[ind] for ind in subset]
  cost = sum(cost_list)
  
  skill_arr = np.zeros(M)
  for ind in subset:
    skill_arr += row_list[ind]
    
  judge = np.min(skill_arr) >= X
    
  return cost, judge

output = np.inf
for j in range(N):
  for subset in combinations(range(N), j):
    cost, judge = check(subset, C_list, row_list, X)
    
    if judge and cost < output:
      output = cost

if output == np.inf:
  output = -1
  
print(output)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
ar=[list(map(int,input().split())) for i in range(n)]
cost=1e9
p=pow(2,n)
for i in range(p):
    temp=[0 for y in range(m+1)]
    pt=bin(i)[2:].zfill(n)
    for j in range(n):
        if pt[j]=='1':
            for k in range(m+1):
                temp[k]+=ar[j][k]
    z=1
    for j in temp:
        if j<x: z=0
    if z: cost=min(temp[0],cost)
if cost==1e9: print(-1)
else: print(cost)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
Q = []
B = [0] * N
C = [0] * (M + 1)
flag = True
MIN = -1
for i in range(N):
  Q.append(list(map(int, input().split())))
  
for i in range(2 ** N):
  B = [0] * N
  C = [0] * (M + 1)
  flag = True
  for j in range(N):
    B[j] = (i >> j) & 1
    
  for j in range(N):
    if B[j] == 1:
      for k in range(M + 1):
        C[k] += Q[j][k]
  for j in range(1, M + 1):
    if C[j] < X:
      flag = False
    if flag == True and (MIN == -1 or MIN > C[0]):
      MIN = C[0]
      
print(MIN)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
ar=[list(map(int,input().split())) for i in range(n)]
cost=1e9
p=pow(2,n)
for i in range(1,p):
    temp=[0 for y in range(m+1)]
    pt=bin(i)[2:].zfill(n)
    for j in range(n):
        if pt[j]=='1':
            for k in range(m+1):
                temp[k]+=ar[j][k]
    z=1
    for j in temp:
        if j<x: z=0
    if z: cost=min(temp[0],cost)
if cost==1e7: print(-1)
else: print(cost)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import itertools
import sys
import copy
N, M, X  = map(int, input().split())
money = []
A = []
ans = 0
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
    
def run(lis, num, A, X, M):
    ans_list =[]
    ans = sum(lis)
    tmp_ans = sum(lis)
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if count == M:
            ans_list.append(sum(list(team)))
    if not len(ans_list) == 0:
        print(min(ans_list))
        sys.exit()
for i in range(2, N+1):
    run(money, i, A, X, M)

print(-1)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
ar=[list(map(int,input().split())) for i in range(n)]
cost=1e7
p=pow(2,n)
for i in range(1,p):
    temp=[0 for y in range(m+1)]
    pt=bin(i)[2:].zfill(n)
    for j in range(n):
        if pt[j]=='1':
            for k in range(m+1):
                temp[k]+=ar[j][k]
    z=1
    for j in temp:
        if j<x: z=0
    if z: cost=min(temp[0],cost)
if cost==1e7: print(-1)
else: print(cost)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int,input().split())
a=[]
b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
c=[]
for i in range(N):
    a.append(input().split())
    c.append(0)

check=0
ans=-1
for i in range(1,pow(2,3)):
    b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    check=0
    for j in range(N):
        if 0x01 & (i >> j):
            for n in range(M+1):
                b[n] = b[n] + int(a[j][n])
    for k in range(1,M):
        if b[k] < X:
            check=1
            break
    if check==0:
        if ans == -1 or ans > b[0]:
            ans = b[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
ar=[list(map(int,input().split())) for i in range(n)]
cost=1e7
p=pow(2,n)
for i in range(p):
    temp=[0 for y in range(m+1)]
    pt=bin(i)[2:].zfill(n)
    for j in range(n):
        if pt[j]=='1':
            for k in range(m+1):
                temp[k]+=ar[j][k]
    z=1
    for j in temp:
        if j<x: z=0
    if z: cost=min(temp[0],cost)
if cost==1e7: print(-1)
else: print(cost)