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 dfs(A):
    if len(A) == n:
        tmp = [0 for i in range(m+1)]
        for i, k in enumerate(A):
            if k:
                for j in range(m+1):
                    tmp[j] += a[i][j]
        chk = 0
        for i in range(1, m+1):
            if tmp[i] >= x:
                chk += 1
        if chk == m:
            ans[0] = min(tmp[0], ans[0])
        return

    for v in range(2):
        A.append(v)
        dfs(A)
        A.pop()


n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [10**10]
dfs([])
print(ans[0])

Submission status: Wrong Answer

Solution code:
import itertools

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

min_cost = 10 ** 5 + 1
for i in range(1, n + 1):
    for j in list(itertools.combinations(range(n), i)):
        recog = [0] * m
        cost = 0
        for k in j:
            cost += c[k]
            for l in range(m):
                recog[l] += a[k][l]

        for l in range(m):
            if recog[l] < x:
                break
        else:
            if cost <= min_cost:
                min_cost = cost

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

Submission status: Wrong Answer

Solution code:
import glob
import os
import numpy as np


bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def rec(self, N, M, X, now_index, now_knowledge, now_price, books):

        if now_index > N:
            return 12 * 10**5 +1

        next_knowledge = now_knowledge + books[now_index][1:]
        if np.min(next_knowledge) >= X:
            result1 = now_price + books[now_index][0]
        else:
            result1 = self.rec(N, M, X, now_index+1, next_knowledge,  now_price + books[now_index][0], books)

        result2 = self.rec(N, M, X, now_index+1, now_knowledge,  now_price, books)

        if result1 < result2:
            return result1
        else:
            return result2

    def resolve(self):

        N, M, X = map(int, self.input_data().split())

        books = [None]*(N+1)
        for i in range(N):
            books[i+1] = np.array(list(map(int, self.input_data().split())))

        print(books)
        print( np.zeros(M))

        result = self.rec(N, M, X, 1, np.zeros(M), 0, books)
        if result == 12 * 10**5 +1:
            print('-1')
        else:
            print(str(result))


solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x=[int(x) for x in input().split()]
book=[]
for i in range(n):
  b=[int(x) for x in input().split()]
  book.append(b)

l=[]
a=itertools.product(range(2),repeat=n)
for i in a:
  l.append(i)

price=[]
for i in range(2**n):
  check_list=[0]*m
  for j in range(n):
    if l[i][j]==1:
      for k in range(m):
        check_list[k]+=book[j][k]
  check=[]
  for p in range(1,m):
    if check_list[p]<x:
      check.append(False)
  if check==[]:
    price.append(check_list[0])

if price==[]:
  print("-1")
else:
  print(min(price))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((N, M))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]
    
answer_price = 2**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1

    if all(tmp >= X) and (cost < answer_price):
        answer_price = cost
        
if answer_price == 2**10:
    print("-1")
else:
    print(int(answer_price))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((N, M))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]
    
answer_price = 2**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1
    if all(tmp >= X) and cost < answer_price:
        answer_price = cost
        
if answer_price == 2**10:
    print("-1")
else:
    print(int(answer_price))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((N, M))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]

answer_price = 2**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1
    if all(tmp >= X) and cost < answer_price:
        answer_price = cost
        
if answer_price == 2**10:
    print("-1")
else:
    print(int(answer_price))

Submission status: Wrong Answer

Solution code:
import itertools

N,M,X= (int(x) for x in input().split(' '))
all_book =[]
min_price = 10**5
c_lst = []
for i in range(N):
    book_lst= [int(x) for x in input().split(' ')]
    all_book.append(book_lst)
for k in range(1,N+1):
    for m in itertools.combinations(all_book, k):
        if len(m) > 1:
            combined1 = [i*0 for i in range(M+1)]
            for i in range(len(m)):
                combined1 = [x + y for (x, y) in zip(combined1, m[i])]
            c_lst.append(combined1)
        elif len(m) == 1:
            c_lst.append(m[0])
for l in range(len(c_lst)):
    if min(c_lst[l][1:M+1]) >= X:
        if min_price > c_lst[l][0]:
            min_price = c_lst[l][0]
if min_price == 10**5:
    min_price = -1

print(min_price)

Submission status: Wrong Answer

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

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

ans = float('inf')
for bit in range(2 ** (N)):
    ten = [0,0,0]
    ans_k = 0
    for i in range(N):
        if bit >> i & 1:
            ten = [x + y for (x, y) in zip(ten, C_A[i][1:])]
            ans_k += C_A[i][0]
            
        if min(ten) >= X:
            ans = min(ans, ans_k)

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

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x= map(int, input().split())
g = []
z = [0]*m
money = []
for _ in range(n):
    a = list(map(int, input().split()))
    y = a.pop(0)
    g.append(a)
    money.append(y)
    for ii,ll in enumerate(a):
      z[ii] += ll
for i in z:
  if i < x:
    print(-1)
    exit(0)
      
ans = 100001
if n <= 6:
  seq = [i for i in range(n)]
  a = list(itertools.permutations(seq))
  for i in a:
    rikai = [0]*m
    num = 0
    for j in i:
      h = 0
      num += money[j]
      for l,k in enumerate(g[j]):
        rikai[l] += k
        if rikai[l] >= x:
          h += 1
      if h == m and ans>num:
        ans = num
        break
  print(ans)
  exit(0)
else:
  seq = [i for i in range(n)]
  a = list(itertools.permutations(seq,6))
  for i in a:
    rikai = [0]*m
    num = 0
    for j in i:
      h = 0
      num += money[j]
      for l,k in enumerate(g[j]):
        rikai[l] += k
        if rikai[l] >= x:
          h += 1
      if h == m and ans>num:
        ans = num
        break
  a = list(itertools.permutations(seq,5))
  for i in a:
    flag = False
    rikai = z
    num = sum(money)
    for j in i:
      h = 0
      num -= money[j]
      for l,k in enumerate(g[j]):
        rikai[l] -= k
        if rikai[l] >= x:
          h += 1
        else:
          flag = True
          break
      if flag:
        break
      if h == m and ans>num:
        ans = num

if ans == 100001:
  print(sum(money))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x= map(int, input().split())
g = []
z = [0]*m
money = []
for _ in range(n):
    a = list(map(int, input().split()))
    y = a.pop(0)
    g.append(a)
    money.append(y)
    for ii,ll in enumerate(a):
      z[ii] += ll
      
ans = 100001
if n <= 6:
  seq = [i for i in range(n)]
  a = list(itertools.permutations(seq))
  for i in a:
    rikai = [0]*m
    num = 0
    for j in i:
      h = 0
      num += money[j]
      for l,k in enumerate(g[j]):
        rikai[l] += k
        if rikai[l] >= x:
          h += 1
      if h == m and ans>num:
        ans = num
        break
  print(ans)
  exit(0)
else:
  seq = [i for i in range(n)]
  a = list(itertools.permutations(seq,6))
  for i in a:
    rikai = [0]*m
    num = 0
    for j in i:
      h = 0
      num += money[j]
      for l,k in enumerate(g[j]):
        rikai[l] += k
        if rikai[l] >= x:
          h += 1
      if h == m and ans>num:
        ans = num
        break
  for i in a:
    flag = False
    rikai = z
    num = sum(money)
    for j in i:
      h = 0
      num -= money[j]
      for l,k in enumerate(g[j]):
        rikai[l] -= k
        if rikai[l] >= x:
          h += 1
        else:
          flag = True
      if flag:
        break
      if h == m and ans>num:
        ans = num
if ans == 100001:
  print(sum(money))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
def main():
    N, M, X = map(int,input().split(' '))
    lines = []
    for i in range(N):
        line = np.array(list(map(int,input().split(' '))))
        lines.append(line)
    flag = True
    ans = []
    for i in range(1,N):
        c_list = np.array(list(itertools.combinations(lines,i)))
        for c in c_list:
            flag = True
            comb = sum(c)
            for a in comb[1:]:
                if a < X:
                    flag = False
                    break
            if flag:
                ans.append(comb)
    if len(ans) == 0:
        print(-1)
    else:
        cost = ans[0][0]
        for answer in ans:
            if cost > answer[0]:
                cost = answer[0]
        print(cost)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
def main():
    N, M, X = map(int,input().split(' '))
    lines = []
    for i in range(N):
        line = np.array(list(map(int,input().split(' '))))
        lines.append(line)
    flag = True
    ans = []
    for i in range(1,N):
        c_list = np.array(list(itertools.combinations(lines,i)))
        for c in c_list:
            flag = True
            comb = sum(c)
            for a in comb[1:]:
                if a < X:
                    flag = False
                    break
            if flag:
                ans.append(comb)
    if len(ans) == 0:
        print(-1)
    else:
        cost = 1000000001
        for answer in ans:
            if cost > answer[0]:
                cost = answer[0]
        print(cost)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n,m,x=map(int,input().split())
A=[[int(i) for i in input().split()] for _ in range(n)]
ans=float("inf")
for i in range(2**n):
  B=[0]*(m+1)
  for j in range(n):
    if i&(1<<j):
      for k in range(m+1):
        B[k]+=A[j][k]
  if min(B[1:])>=x:
    ans=min(ans,B[0])
print(ans)

Submission status: Wrong Answer

Solution code:
def mincuota(listas, N, M, X):
  possibilities = []
  for i in range(N):
    flag = 0
    for j in range(1, M+ 1):
      if(listas[i][j] < X):
        flag = 1
        break
    if(flag == 1):
      continue
    else:
      possibilities.append(listas[i][0])
  if(possibilities != []):
    return min(possibilities)
  for i in range(1, M+ 1):
    skill = 0
    for j in range(N):
      skill+= listas[j][i]
    if(skill < X):
      return -1
  else:
    newcuotas = []
    for i in range(N):
      newlistas = listas[:i]+ listas[i+ 1:]
      if(mincuota(newlistas, N- 1, M, X) != -1):
        newcuotas.append(mincuota(newlistas, N- 1, M, X))
    if(newcuotas == []):
      cuota = 0
      for i in range(N):
        cuota+= listas[i][0]
      return cuota
    else:
      return min(newcuotas)
  
N, M, X = map(int, input().split())
listas = []
for i in range(N):
  listas.append(list(map(int, input().split())))

  
print(mincuota(listas, N, M, X))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = 10**6
for i in range(1,n+1):
  for j in combinations(ca,i):
    check = [0]*(m+1)
    for k in j:
      for a in range(m+1):
        check[a] += k[a]
    if min(check[1:]) >= x:
      ans = min(ans, check[0])

if ans == 10**6:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
ca = [0]*n
for i in range(n):
    ca[i] = list(map(int,input().split()))
ans = 10**10
for i in range(n**2):
    s = [0]*m
    c = 0
    for j in range(n):
        if (i>>j)&1:
            c += ca[j][0]
            for k in range(1,m+1):
                s[k-1] += ca[j][k]
    s = sorted(s)
    if s[0] >= x:
        ans = min(ans,c)
if ans == 10**10:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

for _ in range(N):
  info = list(map(int,input().split()))
  books.append(info)

res = float('inf')
for i in range(1<<N):
  scores = [0] * M
  cost = 0
  for j in range(N):
    if (i>>j)&1:
      for k,p in enumerate(books[j][1:]):
        scores[k] += p
      cost += books[j][0]

  if all([ score >= X for score in scores]):
    res = min(res, cost)

print(res) if res < float('inf') else print('inf')

Submission status: Wrong Answer

Solution code:
import sys

n, m, x =map(int,input().split())
g = []
for _ in range (n):
     array = list(map(int,input().split()))
     g.append(array)
print(g)
#縦が本の数、よこがj番目のアルゴリズム理解度

Submission status: Wrong Answer

Solution code:
import sys

def calcSum(N, BuyingList_bool, Books):
    Price = 0
    for Num in range(N):
        if(BuyingList_bool[Num]):
            Price += Books[Num][0]
    return Price

def search(N, M, X, Books, BuyingList_bool, Prices = [], BranchPos =0):
    if(BranchPos == N):
        Complehensives = [0] * M
        for m in range(M):
            for n in range(N):
                if(BuyingList_bool[n]):
                    Complehensives[m] += Books[n][m+1]
            if(Complehensives[m] < X):
                return None
            else:
                Prices.append( calcSum(N, BuyingList_bool, Books) )
                return Prices
    BuyingList_bool[BranchPos] = True
    search(N, M, X, Books, BuyingList_bool, Prices, BranchPos+1)
    BuyingList_bool[BranchPos] = False
    search(N, M, X, Books, BuyingList_bool, Prices, BranchPos+1)
    return Prices



if(__name__ == '__main__'):
    NMX = input().split()

    N= int(NMX[0].strip())
    M= int(NMX[1].strip())
    X= int(NMX[2].strip())

    Books = []
    AllSum = []
    for Num in range(M+1):
        AllSum.append(0) # [M] -> value
    for Num in range(N):
        List = []
        In = input().split()
        for Str in In:
            List.append(int(Str.strip()))
        Books.append(List)

    Prices = []
    BuyingList_bool = [True] * N
    Prices = search(N, M, X, Books, BuyingList_bool)
    if(len(Prices) ==0):
        print(-1)
    else:
        print( min(Prices) )

Submission status: Wrong Answer

Solution code:
N,M,X = map(int,input().split())
list = []
skill=[0]*M
ans = 10**10
for i in range(N):
    item = input().split()
    list.append(item)
for i in range(2**N):
    skill = [0]*M
    sum = 0
    for j in range(N):
        if ((i >>j) & 1):
            for u in range(M):
                skill[u]+= int(list[j][u+1])
            sum += int(list[j][0])
    if min(skill)>=X:
        ans = min(ans,sum)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from operator import add

def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())
def lim(N):
    return [int(input()) for i in range(N)]

N, M, X = mi()
C = []
A = []
for i in range(N):
    CA = li()
    C.append(CA[0])
    A.append(CA[1:])

Cost = 10 ** 6
for i in range(1, N + 1):
    # 組み合わせを作成する。
    it = itertools.combinations(range(N) ,i)

    # 組み合わせに対しての理解度を合計し、それぞれMを超えているのかを確認する。
    for i in it:
        rikaido = [0] * M
        cur_cost = 0
        for j in i:
            rikaido = list(map(add, rikaido, A[j]))
            cur_cost += C[j]

            rikaiflag = True
            for k in range(M):
                if rikaido[k] < X:
                    rikaiflag = False
                    break
            if rikaiflag:
                Cost = min(Cost,cur_cost)

if Cost == 10 ** 6:
    print(-1)
else:
    print(Cost)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 10**8
for b in range(2**N):
    A_sum = np.zeros(A[0].shape,dtype=np.int32)
    for i in range(N):
        if (b >> i) % 2 == 1:
            A_sum += A[i]
    for i in range(1,M+1):
        if A_sum[i] < X:
            break
    else:
        ans = min(ans,A_sum[0])
print(ans)

Submission status: Wrong Answer

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

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

import itertools
ans=1000000000
for i in itertools.product([0,1], repeat=N):
    cnt = [0] * (M+1)
    for j in range(N):
        for k in range(M+1):
            cnt[k] += A[j][k]*i[j]
    if cnt[1:]>[X]*(M):
        ans = min(ans, cnt[0])
print(ans if ans!=1000000000 else -1 )

Submission status: Wrong Answer

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

# 合否判定のためのフラグ
Flag = False
cost_min = 0
for i in range(n):
  cost_min += cas[i][0]

# 全ての組み合わせについてチェック
for i in range(2**n):
  bag  = [0]*(m+1)
  # バッグに荷物を詰める
  for j in range(n):
    if ((i>>j) & 1):
      for k in range(m+1):
        bag[k] += cas[j][k]
  # 条件を満たしているか調べる
  if (min(bag[1:]) >= 10):
    Flag = True
    cost_min = min(cost_min, bag[0])

if (Flag):
  print(cost_min)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

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

ca = []
for _ in range(N):
  ca.append( list(map(int, input().split())))
ca = np.array(ca)
#print(ca)
ans = 1000000

b = [0,1]
for p in list(itertools.product(b, repeat=N)): 
  a = np.array(p)
  to = a@ca
  if min(to[1:]) >= X:
    ans = min(ans, to[0])
#
if ans == 1000000:
  print(-1)
else:
  print(ans)
#

Submission status: Wrong Answer

Solution code:
def nextg(x, place):
    if x[place] == 1:
        x[place] = 0
        if place == 0:
            return x
        return nextg(x, place-1)
    if x[place] == 0:
        x[place] = 1
        return x
n, m, t = map(int,input().split())
generator = [0]*n
books = []
for i in range(0, n):
    books.append(list(map(int,input().split())))
min = 0
for i in range(0, n):
    min+=books[i][0]
flag = 0
for i in range(0, pow(2,n)):
    found = False
    for k in range(1, m):
        sum = 0
        for j in range(0, n):
            sum+=books[j][k]*generator[j]
        if sum<t:
            break
        elif k == m-1:
            found = True
            flag = 1         
    cost = 0
    for p in range(0, n):
        cost+=books[p][0]*generator[p]
    if found == True and cost<min:
        min = cost
    generator = nextg(generator, n-1)
if flag == 1:
    print(min)
else:
    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)]

ans = float('inf')

print(c)

for i in range(2**n):#行数回す。(１０進数)
    hold = [0] * (m+1)
    for j in range(n):#行数回す（２進数）。flagを立てる。
        if (i >> j) & 1:#　i(二進数)をj個右に動かす。
            for k in range(m+1):
                hold[k] += c[j][k]
    if min(hold[1:]) >= x : 
        ans = min(ans,hold[0])

if ans != float('inf'):
    print(ans)
else:
    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)]

ans = float('inf')

print(c)

for i in range(2**n):#行数回す。(１０進数)
    hold = [0] * (m+1)
    for j in range(n):#行数回す（２進数）。flagを立てる。
        if(i >> j) and 1:#　i(二進数)をj個右に動かす。
            for k in range(m+1):
                hold[k] += c[j][k]
    if min(hold[1:]) >= x : 
        ans = min(ans,hold[0])

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

Submission status: Wrong Answer

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

book = []

for _ in range(n):
  book.append(list(map(int, input().split())))

min_cost = 9999999
  
for i in range(1,2**n):
  b = format(i, 'b')
  b = b.zfill(n)
  cost = 0
  us = [0 for _ in range(m)]
  for j in range(len(b)):
    if int(b[j]) == 1:
      cost += book[j][0]
      for k in range(m):
        us[k] += book[j][k+1]
  
  if sum(a>=x for a in us) == m:
    if cost < min_cost:
      min_cost = cost

if min_cost == 999999:
  print(-1)
else:
  print(min_cost)

Submission status: Wrong Answer

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

book = []

for _ in range(n):
  book.append(list(map(int, input().split())))

min_cost = 999999
  
for i in range(1,2**n):
  b = format(i, 'b')
  b = b.zfill(n)
  cost = 0
  us = [0 for _ in range(m)]
  for j in range(len(b)):
    if int(b[j]) == 1:
      cost += book[j][0]
      for k in range(m):
        us[k] += book[j][k+1]
  
  if sum(a>=x for a in us) == m:
    if cost < min_cost:
      min_cost = cost

if min_cost == 999999:
  print(-1)
else:
  print(min_cost)

Submission status: Wrong Answer

Solution code:
import sys
import pprint
import copy

a,b,c = map(int, input().split())
cnt = 0
flg = 0
work = 0
list1 = [list(map(int, input().split())) for j in range(a)]

list1.sort()

sum = [0 for i in range(b + 1)]

for i in range(a):
  for j in range(b + 1):
    sum[j] += list1[i][j]
    if j != 0 and sum[j] >= c:
      cnt += 1
    if cnt == b:
      flg = 1
      work = i
  cnt = 0
  if flg == 1:
    break

ans = [0 for i in range(b + 1)]
if flg == 1:
  while work >= 0:
    for j in range(b + 1):
      if j == 0:
        ans[j] = sum[j] - list1[work][j]
        continue
      ans[j] = sum[j] - list1[work][j]
      if ans[j] < c:
        cnt = 0
        ans = copy.copy(sum)
        break
      else:
        cnt += 1
      if cnt == b:
        sum = copy.copy(ans)
    work -= 1
else:
  print(-1)
  sys.exit()

print(sum[0])

Submission status: Wrong Answer

Solution code:
# ABC 167 C
N,M,X = map(int,input().split())
C =[]
for m in range(N):
    C.append([int(i) for i in input().split()])
C.sort(key=lambda x:x[0])

from itertools import combinations
import numpy as np


ans = 10**5 +1
cnt=0
for m in range(1,N+1):
    P=list(combinations(C,m))
    tmp =np.sum(P,axis=1)
    for t in tmp:

        if min(t[1:])>=X and ans > t[0]:
            ans = t[0]
            cnt+=1
if cnt>0:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# ABC 167 C
N,M,X = map(int,input().split())
C =[]
for m in range(N):
    C.append([int(i) for i in input().split()])
C.sort(key=lambda x:x[0])

from itertools import combinations
import numpy as np


ans = 10**5 +1

for m in range(1,N+1):
    P=list(combinations(C,m))
    tmp =np.sum(P,axis=1)
    for t in tmp:

        if min(t[1:])>=X and ans > t[0]:
            ans = t[0]
        
          
if min(t[1:])<X:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# ABC 167 C
N,M,X = map(int,input().split())
C =[]
for m in range(N):
    C.append([int(i) for i in input().split()])
C.sort(key=lambda x:x[0])

from itertools import combinations
import numpy as np


ans = 10**5 +1

for m in range(1,N+1):
    P=list(combinations(C,m))
    print(P)
    tmp =np.sum(P,axis=1)
    for t in tmp:

        if min(t[1:])>=X and ans > t[0]:
            ans = t[0]

        
          
if min(t[1:])<X:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# ABC 167 C
N,M,X = map(int,input().split())
C =[]
for m in range(N):
    C.append([int(i) for i in input().split()])
C.sort(key=lambda x:x[0])

from itertools import combinations
import numpy as np


ans = 10**5 +1

for m in range(1,N+1):
    P=list(combinations(C,m))
    print(P)
    tmp =np.sum(P,axis=1)
    for t in tmp:

        if min(t[1:])>=X and ans > t[0]:
            ans = t[0]
        print(t)
        
          
if min(t[1:])<X:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# ABC 167 C
N,M,X = map(int,input().split())
C =[]
for m in range(N):
    C.append([int(i) for i in input().split()])
C.sort(key=lambda x:x[0])

from itertools import combinations
import numpy as np


ans = 10**5 +1

for m in range(1,N+1):
    P=list(combinations(C,m))
    tmp =np.sum(P,axis=1)
    for t in tmp:
        if ans < t[0]:
            print(ans)
            exit()
        elif min(t[1:])>=X and ans > t[0]:
            ans = t[0]
        
          
if min(t[1:])<X:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N,M,X = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
B = list(itertools.product([0,1], repeat=M))
sums = {}
Point = [0]*M
ans = 0
for a,i in zip(A,range(len(A))):
    sum = 0
    for b in B:
        for j in range(M):
            if b[j] == 1:
                sum += a[j+1]
    sums[i] = sum
sums = sorted(sums.items(),reverse=True,key=lambda x:x[1])
for sum in zip(sums):
    for i in range(1,M+1):
        Point[i-1] += A[sum[0][0]][i]
    ans += A[sum[0][0]][0]
    if M == len([Point[i] for i in range(M) if Point[i] >= X]):
        print(ans)
        exit(0)
print(-1)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int,input().split())
Book = [[] for _ in range(N)]
mi = float('inf')
for i in range(N):
    Book[i] = list(map(int,input().split()))
for j in range(2**N):
    s = [0 for _ in range(N)]
    k = str(bin(j))[2:]
    o = len(k)
    x = 0
    B = [0 for u in range(M)]
    for l in range(o):
        s[N-l-1]= int(k[o-l-1])
    for p in range(N):
        if s[p] == 1:
            x += Book[p][0]
            for q in range(1,M+1):
                B[q-1] += Book[p][q]
    for n in range(M):
        if B[n] < X:
            break
        if x < mi:
            mi = x
if mi == float('inf'):
    print(-1)
    exit()
print(mi)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split(' '))
input_lists = [list(map(int, input().split(' '))) for _ in range(n)]
 
comb = []
for i in range(2 ** n):
    tmp = []
    for j in range(n):
        if ((i >> j) & 1):
            tmp.append(input_lists[j])
    comb.append(tmp)

result = -1
for i in range(len(comb)):
    understand = [0]*m
    total_fee = 0
    for j in range(len(comb[i])):
        total_fee += comb[i][j][0]
        for k in range(1, m):
            understand[k] += comb[i][j][k]
    boolean = True
    for j in range(m):
        if all(t < x for t in understand):
            boolean = False
    if boolean and (result == -1 or result > total_fee):
        result = total_fee
 
print(result)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split(' '))
input_lists = [list(map(int, input().split(' '))) for _ in range(n)]
 
comb = []
for i in range(2 ** n):
    tmp = []
    for j in range(n):
        if ((i >> j) & 1):
            tmp.append(input_lists[j])
    comb.append(tmp)

result = -1
for i in range(len(comb)):
    understand = [0]*m
    total_fee = 0
    for j in range(len(comb[i])):
        total_fee += comb[i][j][0]
        for k in range(1, m):
            understand[k] += comb[i][j][k]
    boolean = True
    for j in range(m):
        if all(t < x for t in understand):
            boolean = False
    if boolean and (result == -1 or result > understand[0]):
        result = total_fee
 
print(result)

Submission status: Wrong Answer

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

comb = []
for i in range(2 ** n):
    tmp = []
    for j in range(n):
        if ((i >> j) & 1):
            tmp.append(input_lists[j])
    comb.append(tmp)

result = -1
for i in range(len(comb)):
    understand = [0]*m
    total_fee = 0
    for j in range(len(comb[i])):
        total_fee += comb[i][j][0]
        for k in range(m):
            understand[k] += comb[i][j][k]
    boolean = True
    for j in range(m):
        if understand[j] < x:
            boolean = False
    if boolean and (result == -1 or result > understand[0]):
        result = total_fee

print(result)