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())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()

sums = [0] * M
able = True
for a in A:
    for i in range(M):
        sums[i] += a[i+1]

for s in sums:
    if s < X:
        able = False

if not able:
    print('-1')
    exit()


import itertools

for i in range(1, N+1):
    P = list(itertools.combinations(range(N), i))
    res = float('inf')
    bkFlg = False
    for p in P:
        price = 0
        x = [0]*M
        for j in list(p):
            a = A[j]
            price += a[0]
            for k in range(1, len(a)):
                x[k-1] += a[k]
            flg = True
            for _x in x:
                if _x < X:
                    flg = False
                    break
            if flg:
                res = min(res, price)
                bkFlg = True
                break
    if bkFlg:
        print(res)
        exit()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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


minimum = 10**20
for pat in range(0, (1<<n)): #参考書の選び方の全パターン
    cost = 0
    rikaido = [0] * m
    for i in range(n):
        if((pat >> i) & 1): #i番目の参考書を読む
            cost += a_do[i][0]
            for k in range(m):
                rikaido[k] += a_do[i][k]
    ok = True
    for k in range(m):
        if(rikaido[k] < x):
            ok = False
    if(ok):
        minimum = min(minimum, cost)

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

Submission status: Wrong Answer

Solution code:
from operator import add
N,M,X = map(int, input().split())
tmp = [list(map(int,list(input().split()))) for i in range(N)]
c= []
a = [[] for i in range(N)]
result = []
for i in range(N):
    c.append(tmp[i][0])
    a[i].extend(tmp[i][1:])

for bit in range(1 << (N)):
    suma = [0] * M
    disc = [X] * M
    c4i = []
    rsum = 0
    for i in range(N):
        if (bit & (1<<i)):
            suma = map(add,suma,a[i])
            c4i.append(i)
    suma = list(suma)
    if suma >= disc:
        for t in c4i:
            rsum = rsum + c[t]
        result.append(rsum)

if result:
    print(min(result))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

N,M,X= map(int, input().split())
C =[]
A =[]
ans = []
ANS =[]
count = 0
COUNT = 0
for i in range(N):
    C = list(map(int,input().split()))
    A.append(C)
for i in range(1,N+1):
    L = list(itertools.combinations(A, i))
    L = np.array(L)
    for i in L:
        Z=np.array([0]*(M+1))
        for j in i:
            Z = Z + j
            flag = False
        ans.append(Z)
for i in ans:
    count = 0
    for j in range(1,M+1):
        if(i[j] < X):
            break
        if(i[j] >= X):
            count += 1
        if(count == M):
            COUNT += 1
        ANS.append(i)
ANS.sort(key=lambda x: x[0])
if COUNT == 0:
    print(-1)
    exit(0)
print(ANS[0][0])

Submission status: Wrong Answer

Solution code:
from operator import add
N,M,X = map(int, input().split())
tmp = [list(map(int,list(input().split()))) for i in range(N)]
c= []
a = [[] for i in range(N)]
result = []
for i in range(N):
    c.append(tmp[i][0])
    a[i].extend(tmp[i][1:])

print(c,a)
for bit in range(1 << (N)):
    suma = [0] * M
    disc = [X] * M
    c4i = []
    rsum = 0
    for i in range(N):
        if (bit & (1<<i)):
            suma = map(add,suma,a[i])
            c4i.append(i)
    suma = list(suma)
    if suma >= disc:
        for t in c4i:
            rsum = rsum + c[t]
        result.append(rsum)

if result:
    print(min(result))
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(1, 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))
    
else:
  print('-1')

Submission status: Wrong Answer

Solution code:
import numpy as np

def plus_score(book_number, now_score, least):
    now_score += get_point[book_number]
    if now_score[0] >= least:
        # print(now_score)
        # print("over")
        return least
        
    # print(now_score)
    # print(now_score[1:][[now_score[1:] < score]])
    if len(now_score[1:][[now_score[1:] < score]]) == 0:
        # print("OK")
        return now_score[0]
    
    else:
        for i in range(book_number+1, book):
            least = plus_score(i, now_score.copy(), least)
    return least
    
    
    
global book
global score
book, skill, score = map(int, input().split())
global get_point
get_point = np.array([])
for _ in range(book):
    get_point = np.append(get_point, np.array(list(map(int, input().split()))))
get_point = get_point.reshape(book, -1)
# print(get_point)
a = 0
least = sum(get_point[:, 0])
for i in range(book):
    less = plus_score(i, np.zeros(skill+1), least)
    if less < least:
        least = less
        a = 1

if a == 1:
    print(int(least))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from collections import deque

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

row = [i for i in range(1, N+1)]
ans = float("INF")
for i in range(1, N):
  for v in combinations(row, i):
    q = deque(v)
    cost = 0
    Asum = [0]*M
    while q:
      a = q.popleft() - 1
      cost += CA[a][0]
      for j in range(M):
        Asum[j] += CA[a][j+1]
    flag = True
    for m in range(M):
      if Asum[m] < X:
        flag = False
    if flag:
      ans = min(ans, cost)
if ans == float("INF"):
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np


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

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

a = np.array(a)
l = np.array(list(itertools.product([0,1], repeat=n)))

ans = sum(c)

for i in l:
	b = np.dot(i,a)
	s = sum(k >= x for k in b)
	if s == m:
		ans = min(sum(i*c), ans)
		
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import combinations_with_replacement

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

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M):
  if sums[i] < X:
    OK = False
    break
    
As = []
for A in combinations_with_replacement(range(0, N), r=M):
  As.append(set(A))

    
if OK == False:
  print(-1)
else:
  min_ = sums[0]
  for i in As:
    mini_CA = []
    for j in i:
      mini_CA.append(CA[j])
    mini_CA = np.array(mini_CA)
    OK2 = True
    sums = np.sum(mini_CA,axis=0)
    for k in range(1,M):
      if sums[k] < X:
        OK2 = False
        break
    if OK2 == True and sums[0] < min_:
      min_ = sums[0]
  print(min_)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
if __name__ == "__main__":
    N, M, X = map(int, input().split())
    ca_ls = []
    for i in range(N):
        ca_ls += [list(map(int, input().split()))]
    ca_ls = np.asarray(ca_ls)
    # print(ca_ls)
    a_ls = ca_ls[:,1:]
    # print(a_ls)
    a_sum = a_ls.sum(axis=1)
    # print(a_sum)
    a_max_index = np.argmax(a_sum)
    # print(a_max_index)
    # print(ca_ls)
    max_ca_row = ca_ls[a_max_index]
    # cnt = -1
    # print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque
from collections import Counter
from collections import OrderedDict
from itertools import combinations as cmb

def check(s: list):
    if min(s) < X:
        return False
    return True

N, M, X = map(int, input().split())
G = [tuple(map(int, input().split())) for _ in range(N)]
s = [0 for i in range(M)]

res = 10 ** 15
for i in range(1, N + 1):
    for cm in cmb(range(0, N), i):
        cnt = 0
        s = [0 for i in range(M)]
        for c in cm:
            cnt += G[c][0]
            for j in range(M):
                s[j] += G[c][j + 1]
        if check(s):
            res = min(cnt, res)

print(res)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

N,M,X= map(int, input().split())
C =[]
A =[]
ans = []
ANS =[]
count = 0
COUNT = 0
for i in range(N):
    C = list(map(int,input().split()))
    A.append(C)
for i in range(1,N+1):
    L = list(itertools.combinations(A, i))
    L = np.array(L)
    for i in L:
        Z=np.array([0]*(M+1))
        for j in i:
            Z = Z + j
            flag = False
        ans.append(Z)
for i in ans:
    count = 0
    for j in range(1,M+1):
        if(i[j] < X):
            break
        if(i[j] >= X):
            count += 1
            if(count == M):
                COUNT += 1
        ANS.append(i)
ANS.sort(key=lambda x: x[0])
if COUNT == 0:
    print(-1)
    exit(0)
print(ANS[0][0])

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(-1 if total == m*(10**5) else total)

Submission status: Wrong Answer

Solution code:
# 1<= N,M <=12
# 1<= X <=10**5
# 1<= C <= 10**5
# 0<= A <=10**5
from itertools import combinations
N, M, X = map(int, input().split())

books = [list(map(int, input().split())) for _ in range(N)]
min_cost = 10**100
flag = False
# print(books)
for i in range(1, M + 1):
    combies = list(map(list, (combinations(list(range(N)), i))))
    # print(combies)
    for combi in combies:
        cost = 0
        skills = [0 for _ in range(M)]
        for book_i in combi:
            cost += books[book_i][0]
            for skill_i, skill_point in enumerate(books[book_i][1:]):
                skills[skill_i] += skill_point
        # print(cost, skills)
        ok = True
        for skill_point in skills:
            if skill_point < X:
                ok = False
                break
        if ok:
            flag = True
            min_cost = min(min_cost, cost)
if flag:
    print(min_cost)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

def function(CA, n, total, skill, C, X_l):
  CAn = CA[n]
  An = CAn[1:]
  skill = np.array(skill) + np.array(An)
  skill = skill.tolist()
  total += CAn[0]
  if skill >= X_l:
    C.append(total)
  return total, skill, C

C = []
X_l = [X]*M
for a in range(N):
  total = 0
  skill = [0]*M
  total, skill_a, C = function(CA, a, total, skill, C, X_l)
  if a == N-1:
    break
  for b in range(a+1, N):
    total, skill_b, C = function(CA, b, total, skill_a, C, X_l)
    if b == N-1:
      break
    for c in range(b+1, N):
      total, skill_c, C = function(CA, c, total, skill_b, C, X_l)
      if c == N-1:
        break
      for d in range(c+1, N):
        total, skill_d, C = function(CA, d, total, skill_c, C, X_l)
        if d == N-1:
          break
        for e in range(d+1, N):
          total, skill_e, C = function(CA, e, total, skill_d, C, X_l)
          if e == N-1:
            break
          for f in range(e+1, N):
            total, skill_f, C = function(CA, f, total, skill_e, C, X_l)
            if f == N-1:
              break
            for g in range(f+1, N):
              total, skill_g, C = function(CA, g, total, skill_f, C, X_l)
              if g == N-1:
                break
              for h in range(g+1, N):
                total, skill_h, C = function(CA, h, total, skill_g, C, X_l)
                if h == N-1:
                  break
                for i in range(h+1, N):
                  total, skill_i, C = function(CA, i, total, skill_h, C, X_l)
                  if i == N-1:
                    break
                  for j in range(i+1, N):
                    total, skill_j, C = function(CA, j, total, skill_i, C, X_l)
                    if j == N-1:
                      break
                    for k in range(j+1, N):
                      total, skill_k, C = function(CA, k, total, skill_j, C, X_l)
                      if k == N-1:
                        break
                      for l in range(k+1, N):
                        total, skill_l, C = function(CA, l, total, skill_k, C, X_l)

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

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(2**N):
    b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(N):
        if 0x01 & (i >> j):
            for n in range(M+1):
                b[n] = b[n] + int(a[j][n])
        check=0
        #print(b)
        for k in range(1,M):
            if b[k] < X:
                #print(k)
                check=1

        if check==0:
            #print(ans)
            if ans == -1 or ans > b[0]:
                ans = b[0]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

#標準出力からの読み込み
input_1 = input()
n = int(input_1.split(" ")[0])
m = int(input_1.split(" ")[1])
x = int(input_1.split(" ")[2])

knowledge = []
for i in range(n):
    input_array = [int(s) for s in input().split(" ")]
    knowledge.append(input_array)

#判定ロジック
#そのそも、目標を達成できない場合は終わり
output = '0'
for i in range(m):
    sum = 0
    for j in range(n):
        sum += knowledge[j][i]
    if sum < x:
        output = '-1'

if output == '-1':
    print(output)
    exit()

tmp_sum = 0
for i in range(n):
    tmp_sum += knowledge[i][0]

cost = tmp_sum
pattern = '{:0' + str(n) + 'b}'
#高々12個の最適化なので総当たりで調べる
for i in range(2**n):
    tmp_cost = 0
    skill_array = [0 for s in range(m)]
    for j in range(n):
        if pattern.format(i)[j] == "1":
            tmp_cost += knowledge[j][0]
            skill_array = list(map(lambda x,y: x + y, skill_array, knowledge[j][1:]))

    for j in range(m):
        if skill_array[j] < x:
            break
    else:
        if cost > tmp_cost:
            cost = tmp_cost

output = cost
print(output)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
a = [[None for _ in range(m+1)] for _ in range(n)]
for i in range(n):
  a[i] = list(map(int,input().split()))
 
a.sort(key=lambda x:x[0])
nsum = 1000000
for t in range(n):
  for l in range(n):
    sum = [0 for _ in range(m+1)]
    for i in range(l,n):
      for j in range(m+1):
        sum[j] += a[i][j]
      for k in range(1,m+1):
        if(sum[k] < x):
          break
      else:
        if(sum[0] < nsum):
          nsum = sum[0]
  a.append(a.pop(0))
print(nsum)

Submission status: Wrong Answer

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

for i in range(n):
    a=list(map(int,input().split()))
    l.append(a)
ans=99999999
for i in range(2 ** n):
    bag = []
    for j in range(n):  
        if ((i >> j) & 1): 
            bag.append(l[j])  
    skill=[0]*m
    enou=[0]*m
    mone=0
    for sub in bag:
        mone+=sub[0]
        for kk in range(1,m+1):
            skill[kk-1]+=sub[kk]
            if skill[kk-1]>=x:
                enou[kk-1]+=1
    if sum(enou)==m:
        if ans>mone:
            ans=mone
if ans==99999999:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

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

kingakumin = 10000000000

for i in range(2 ** n):
    now = []
    inow = i
    for j in range(n):
        now.append(i % 2)
        i = i // 2

    syuutoku = []
    for j in range(m):
        syuutoku.append(0)

    kingaku = 0
    for j in range(n):
        if now[j] == 1:
            kingaku = kingaku + cas[j][0]
            for k in range(m):
                syuutoku[k] = syuutoku[k] + cas[j][k + 1]

    flag = True
    for j in range(m):
        if syuutoku[j] < x:
            flag = False

    if flag and kingakumin > kingaku:
        kingakumin = kingaku

if kingakumin == 10000000000:
    kingakumin = 0

print(kingakumin)

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(1, 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:
N, M, X = map(int,input().split())
a=[]
b=[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(2**N):
    b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(N):
        if 0x01 & (i >> j):
            for n in range(M+1):
                b[n] = b[n] + int(a[j][n])
        check=0
        #print(b)
        for k in range(1,M):
            if b[k] < X:
                #print(k)
                check=1

        if check==0:
            #print(ans)
            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())
C = []
for i in range(N):
    C.append(list(map(int,input().split())))

cost = 100000000000000000000000
l = list(range(1,N+1))
import itertools
for i in range(1,N+1):
    check_l = list(itertools.combinations(l,i))
    for a in check_l:
        sub_list = [0] * (M + 1)
        for j in range(i):
            for k in range(M+1):
                sub_list[k] += C[a[i-1]-1][k]
        flag = True
        for p in range(M):
            if sub_list[p+1] < X:
                flag = False
        if flag == True:
            if cost > sub_list[0]:
                cost = sub_list[0]

if cost == 100000000000000000000000:
    print(-1)
else:
    print(cost)

Submission status: Wrong Answer

Solution code:
# 1<= N,M <=12
# 1<= X <=10**5
# 1<= C <= 10**5
# 0<= A <=10**5
from itertools import combinations
N, M, X = map(int, input().split())

books = [list(map(int, input().split())) for _ in range(N)]
min_cost = 10**100
# print(books)
for i in range(1, M + 1):
    combies = list(map(list, (combinations(list(range(N)), i))))
    # print(combies)
    for combi in combies:
        cost = 0
        skills = [0 for _ in range(M)]
        for book_i in combi:
            cost += books[book_i][0]
            for skill_i, skill_point in enumerate(books[book_i][1:]):
                skills[skill_i] += skill_point
        # print(cost, skills)
        ok = True
        for skill_point in skills:
            if skill_point < X:
                ok = False
                break
        if ok:
            min_cost = min(min_cost, cost)
if min_cost == 10**100:
    print('-1')
else:
    print(min_cost)

Submission status: Wrong Answer

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

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

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

min_cost = 12*10**5


def dfs(CA, cost, skills, cur, used, min_cost):
  #Pdb().set_trace()
  #print(cur)
  skills = [skills[i] + n for i, n in enumerate(CA[cur][1:])]
  used += [cur]
  cost += CA[cur][0]
  
  if all([s >= X for s in skills]):
  	return cost
  else:
    candidates = [n for n in range(N) if n not in used]
    prev_used = used
    prev_skills = skills
    prev_cost = cost
    for i in candidates:
        min_cost = min(min_cost, dfs(CA, prev_cost, prev_skills, i, prev_used, min_cost))
  return min_cost
       

for i in range(N):
  #Pdb().set_trace()
  used = []
  cost = 0
  skills = [0] * M
  min_cost = min(min_cost, dfs(CA, cost, skills, i, used, min_cost)) 

if min_cost == 12*10**5:
  print(-1)
else:
  print(min_cost)

Submission status: Wrong Answer

Solution code:
# 1<= N,M <=12
# 1<= X <=10**5
# 1<= C <= 10**5
# 0<= A <=10**5
from itertools import combinations
N, M, X = map(int, input().split())

books = [list(map(int, input().split())) for _ in range(N)]
min_cost = 10**100
# print(books)
for i in range(1, M + 1):
    combies = list(map(list, (combinations(list(range(N)), i))))
    # print(combies)
    for combi in combies:
        cost = 0
        skills = [0 for _ in range(M)]
        for book_i in combi:
            cost += books[book_i][0]
            for skill_i, skill_point in enumerate(books[book_i][1:]):
                skills[skill_i] += skill_point
        # print(cost, skills)
        ok = True
        for skill_point in skills:
            if skill_point < X:
                ok = False
                break
        if ok:
            min_cost = min(min_cost, cost)
if min_cost == 10**100:
    print(-1)
else:
    print(min_cost)

Submission status: Wrong Answer

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

  for y in range(n):
    a=copy.deepcopy(b)
    for p in range(y,n):
      for k in range(1,m):
    #print(p)
        a[k]-=c[p][k]
        if a[k]<x:
      #print(k)
          min_a0=min(a[0],min_a0)
          for q in range(k+1):
            a[q]+=c[p][q]
          break
      a[0]-=c[p][0]
      
  d=sorted(c,key=lambda x: x[0],reverse=False)
  a=copy.deepcopy(b)
  for y in range(n):
    a=copy.deepcopy(b)
    for p in range(y,n):
      for k in range(1,m):
    #print(p)
        a[k]-=d[p][k]
        if a[k]<x:
      #print(k)
          min_a0=min(a[0],min_a0)
          for q in range(k+1):
            a[q]+=d[p][q]
          break
      a[0]-=d[p][0]
  
  
  #print(a[0])
  print(min_a0)
main()

Submission status: Wrong Answer

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

cost=0
a = list(map(int,input().split()))
n=a[0]
m=a[1]
x=a[2]
b = [str(input()) for i in range(n)]
calist=[]
for ii in range(n):
    calist.append(list(map(int,b[ii].split())))
temparry=list(itertools.permutations(range(n)))
flagtmp=False
for ll in range(len(temparry)):
    tempcost=0
    flag=False
    l = [0] * m
    for iii in range(n):
        tempcost=tempcost+calist[temparry[ll][iii]][0]
        for iiii in range(m):
            l[iiii]=l[iiii]+calist[temparry[ll][iii]][iiii+1]
        if(min(l)>=x):
            flag=True
            break
    if(ll==1):
        cost=tempcost
    if(flag):
        flagtmp=True
        if(tempcost<cost):
            cost=tempcost
            
if(cost!=0 and flagtmp):
    print(cost)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
a = [[None for _ in range(m+1)] for _ in range(n)]
for i in range(n):
  a[i] = list(map(int,input().split()))

a.sort(key=lambda x:x[0])
nsum = 1000000
for t in range(n):
  for l in range(n):
    sum = [0 for _ in range(m+1)]
    for i in range(l,n):
      for j in range(m+1):
        sum[j] += a[i][j]
      for k in range(1,m+1):
        if(sum[k] < x):
          break
      else:
        if(sum[0] < nsum):
          nsum = sum[0]
    print(sum)
  a.append(a.pop(0))
print(nsum)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!


n,m,x = map(int,input().split())
A = [0 for i in range(m + 1)]
L = []
for i in range(n):
    L.append(list(map(int,input().split())))
    
    for j in range(m + 1):
        A[j] = int(A[j]) + L[i][j]
L.sort(key=lambda x: x[1], reverse=True)
#print(L)

for i in L:
    for j in range(m):
        if A[j+1] - i[j+1] <x:
            break
    else:
        for k in range(m+1):
            A[k] = A[k] - i[k]
    
#print(A)
for i in range(m):
    if A[i+1]<x:
        print(-1)
        break
else:
    print(A[0])

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)
    bug.pop(0)
    if len(clear) > 0:
        O = clear.pop(0)

    if len(bug) == len(clear):
        ways.append(O)

    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:
# 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):
    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 sum(list(team)) < tmp_ans and count == num:
            tmp_ans = sum(list(team))
    if not tmp_ans == sum(lis):
        print(tmp_ans)
        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 = (int(x) for x in input().split())

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

# 値段の安い順に並び替え
book_list.sort()
# print(book_list)

ans = -1

skill_list = [0] * m

for j in range(n) :

    clear = True

    for i in range(m) :
        # print(' i :  {} '.format(i))
        skill_list[i] = skill_list[i] + book_list[j][i]

    for k in range(1, m) :
        # print(' skill_lise[k] :  {} '.format(skill_list[k]))
        if skill_list[k] < x :
            clear = False

    if clear == True :
        ans = skill_list[0]
        break

print(ans)

Submission status: Wrong Answer

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

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

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

min_cost = 12*10**5


def dfs(CA, cost, skills, cur, used, min_cost):
  #Pdb().set_trace()
  #print(cur)
  skills = [skills[i] + n for i, n in enumerate(CA[cur][1:])]
  used += [cur]
  cost += CA[cur][0]
  
  if all([s >= X for s in skills]):
  	return cost
  else:
    candidates = [n for n in range(N) if n not in used]
    prev_used = used
    prev_skills = skills
    prev_cost = cost
    for i in candidates:
        min_cost = min(min_cost, dfs(CA, prev_cost, prev_skills, i, prev_used, min_cost))
  return min_cost
       

for i in range(N):
  #Pdb().set_trace()
  used = []
  cost = 0
  skills = [0] * M
  min_cost = min(min_cost, dfs(CA, cost, skills, i, used, min_cost)) 

print(min_cost)

Submission status: Wrong Answer

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

b = [i for i in range(N)]
n = len(b)

b_pairs = []
for i in range(1, n+1):
    b_pairs += list(itertools.combinations(b, i))

cnt = 0
A = [0] * M
B = []
C = []
for i in range(2 ** N - 1):
  w = len(b_pairs[i])
  for j in range(M):
    for k in range(w):
      A[j] += l[b_pairs[i][k]][j + 1]
  B.append(A)
  A = [0] * M
  
for i in range(2 ** N - 1):
  w = len(b_pairs[i])
  for k in range(w):
    cnt += l[b_pairs[i][k]][0]
  C.append(cnt)
  cnt = 0

for i in range(len(B)):
  for j in range(M):
    if B[i][j] >= X:
      pass
    else:
      B[i] = 0
      break

if B == 0:
  print(-1)

for i in range(len(B)):
  if B[i] != 0:
    B[i] = C[i]
  else:
    B[i] = 1000000000000

print(min(B))