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:
from copy import deepcopy

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

CAS = [[int(i) for i in input().split()] for _ in range(N)]


ok = False
mi = [float('inf'), *[0]*(M-1)]

fs = '{:0' + str(N) + 'b}'

for i in range(2**N):
  s = fs.format(i)
  t = [0]*M
  for i, f in enumerate(s):
    if f == '1':
      t = [a+b for a, b in zip(CAS[i], t)]

  if all(a >= X for a in t[1:]) and mi[0] > t[0]:
    mi = t
    ok = True


if ok:
  print(mi[0])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

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

CAS = [[int(i) for i in input().split()] for _ in range(N)]


ok = False
mi = [float('inf'), *[0]*(M-1)]

fs = '{:0' + str(N-1) + 'b}'

for i in range(2**N):
  s = fs.format(i)
  t = [0]*M
  for i, f in enumerate(s):
    if f == '1':
      t = [a+b for a, b in zip(CAS[i], t)]

  if all(a >= X for a in t[1:]) and mi[0] > t[0]:
    mi = t
    ok = True


if ok:
  print(mi[0])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
#ABC167
N,M,X=map(int,input().split())
c = []  #参考書の値段
a = []  #各参考書に入る理解度
for i in range(N):
    c_temp, *a_temp = list(map(int, input().split()))  # こうすると、2つ目以降をリストで受け取れる
    c.append(c_temp)
    a.append(a_temp)
price_min = 10000000
for i in range(2**N):
    price_total = 0  #値段の合計
    learn_total = [0] * M #理解度の合計
    for j in range(N):
        if (i >> j) & 1:  # j桁目が0か1か見て、j冊目を買うか買わないか判定します
            price_total += c[j]  # 買うので、j冊目の値段を加算します
            learn = a[j]  # 「j冊目の参考書を読んで増える、各アルゴリズムの理解度」のリストです
            for k, la in enumerate(learn):  # 理解度を加算します enumerateを使うと、range(n)よりスマートです
                learn_total[k] += la
    if all(learn_total[k] >= X for k in range(M)):
        if price_min > price_total:
            price_min=price_total
            
if price_min==100000:
    print (-1)
else:
    print (price_min)

Submission status: Wrong Answer

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

# 入力をすべて受け取る
for i in range(n):
  tmp = list(map(int, input().split()))
  inp.append(tmp)

# bit全探索を行うための箱づくり
sum = 0
min = 10**10
for i in range(2**n):
  tmp = [0]*m
  flg = 0
  
  # ある買う買わないのケースに対して、フラグが立ってたらスキルポイントを増やす
  for j in range(n):
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      sum += inp[j][0]
      for k in range(1,m+1):
        #print(n,j, k, tmp, inp)
        tmp[k-1] += inp[j][k]
  for k in range(1,len(tmp)):
    if tmp[k] < x: # x未満ならflgをたててNGとする
      flg = 1
      break
  if sum < min and flg == 0: min = sum
  sum = 0
  
if min == 10**10: min = -1
print(min)

Submission status: Wrong Answer

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

# 入力をすべて受け取る
for i in range(n):
  tmp = list(map(int, input().split()))
  inp.append(tmp)

# bit全探索を行うための箱づくり
sum = 0
min = 10**10
for i in range(2**n):
  tmp = [0]*m
  flg = 0
  
  # ある買う買わないのケースに対して、フラグが立ってたらスキルポイントを増やす
  for j in range(n):
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      sum += inp[j][0]
      for k in range(1,m):
        #print(j, k, tmp, inp)
        tmp[k] += inp[j][k]
  for k in range(1,len(tmp)):
    if tmp[k] < x: # x未満ならflgをたててNGとする
      flg = 1
      break
  if sum < min and flg == 0: min = sum
  sum = 0
  
if min == 10**10: min = -1
print(min)

Submission status: Wrong Answer

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

# 入力をすべて受け取る
inp = []
for i in range(n):
  tmp = []
  tmp = list(map(int, input().split()))
  inp.append(tmp)

#print(inp)

# bit全探索を行うための箱づくり
tmp = [0]*m
flg = 0
sum = 10**10
min = 10**10
for i in range(2**n):
  
  # ある買う買わないのケースに対して、フラグが立ってたらスキルポイントを増やす
  for j in range(n):
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      sum += inp[j][0]
      for k in range(1,m):
        #print(j, k, tmp, inp)
        tmp[k] += inp[j][k]
  #print(sum, tmp)
  tt = tmp.pop(0)
  for k in tmp:
    if k < x: 
      flg = 1
      break
  if sum < min and flg == 0: min = sum
  tmp = [0]*m
  sum = 0
  flg = 0
if min == 10**10: min = -1
print(min)

Submission status: Wrong Answer

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

# 入力をすべて受け取る
inp = []
for i in range(n):
  tmp = []
  tmp = list(map(int, input().split()))
  inp.append(tmp)

#print(inp)

# bit全探索を行うための箱づくり
tmp = [0]*m
flg = 0
sum = 10**10
min = 10**10
for i in range(2**n):
  
  # ある買う買わないのケースに対して、フラグが立ってたらスキルポイントを増やす
  for j in range(n):
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      sum += inp[j][0]
      for k in range(1,m):
        #print(j, k, tmp, inp)
        tmp[k] += inp[j][k]
  #print(sum, tmp)
  tt = tmp.pop(0)
  for k in tmp:
    if k < x: 
      flg = 1
      break
  if sum < min and flg == 0: min = sum
  tmp = [0]*m
  sum = 0
  flg = 0
print(min)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
books = [list(map(int,input().split())) for _ in range(n)]
ans = 11 * (10**5) + 1
for i in range(2**n):
    kingaku = 0
    rikaido = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            kingaku += books[j][0]
            for k in range(m):
                rikaido[k] += books[j][k+1]
    if all((a >= x for a in rikaido)):
        ans = min(ans,kingaku)
if ans != 11 * (10**5) + 1:
    print(ans)
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
book = [list(map(int,input().split())) for _ in range(n)]
ans = 12 * (10**5) + 1
for i in range(2**n):
    kingaku = 0
    rikaido = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            kingaku += book[j][0]
            for k in range(m):
                rikaido[k] += book[j][1]
    if all((a >= x for a in rikaido)):
        ans = min(ans,kingaku)
if ans != 12 * (10**5) + 1:
    print(ans)
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

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

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

    #bit全探索 買う・買わないを判断する
    INF = 10**19
    ans = INF
    for x in range(2**n):
        ALG = [0]*m
        gokei = 0
        for y in range(n):
            if (x>>y) & 1:
                #print(A[y])
                #取得する配列が決まったら、アルゴリズム理解度を＋していく
                for j in range(m):
                    ALG[j] += A[y][j+1]
                gokei += A[y][0]
        #print("ALG="+str(ALG))
        #Alg配列の中身がすべて理解度xを超えているかのチェック
        algflg=True
        for k in ALG:
            if k < a:
                algflg=False
                break
        if algflg:
            ans = min(ans,gokei)
    if ans == INF:
        print("-1")
    else:
        print(ans)

Submission status: Wrong Answer

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

ans = float('inf')
for i in range(2**n):
    tmp = [0]*(m-1)
    cost = 0
    for j in range(n):
        if (i >> j) & 1:
            for k in range(m-1):
                tmp[k] += cl[j][k+1]
            cost += cl[j][0]
    for t in tmp:
        if t < x:
            break
    else:
        ans = min(ans, cost)

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

Submission status: Wrong Answer

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

ans = 1001001001
for i in range(2**n):
    tmp = [0]*(m-1)
    cost = 0
    for j in range(n):
        if (i >> j) & 1:
            for k in range(m-1):
                tmp[k] += cl[j][k+1]
            cost += cl[j][0]
    for t in tmp:
        if t < x:
            break
    else:
        ans = min(ans, cost)

if ans == 1001001001:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N,M,X = map(int,input().split())
B=[0]*N
for i in range(N):
    B[i]=list(map(int, input().strip().split()))

x=N*10**5
sum_ok = N*10**5
unst =[0]*(M)

def all0(v):
    return 0


for i in range(2**N):
    # print(bin(i))
    sum = 0
    unst = list(map(all0,unst))
    for j in range(N):
        if (i >> j) & 1 :
            # print(j)
            sum += B[j][0]
            # unst = list(map(lamda:x,x+B[j][]))
            for k in range(M):
                unst[k]+=B[j][k+1]
    # print(unst)
    # print("sum=",sum)
    if all(elem >= X for elem in unst):
        sum_ok = sum
    x=min(x,sum_ok)
    # print(x)
        
# print(unst)

if x == N*10**5:
    print(-1)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
#
# abc167 c
#
import sys
from io import StringIO
import unittest
from collections import deque


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3 10
60 2 2 4
70 8 7 9
50 2 3 9"""
        output = """120"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 3 10
100 3 1 4
100 1 5 9
100 2 6 5"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """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"""
        output = """1067"""
        self.assertIO(input, output)


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

    ans = float("inf")
    for bit in range(1 << N):
        S = [0]*(M+1)
        for i, ca in enumerate(CA):
            if (1 << i) & bit == 1 << i:
                S = list(map(sum, zip(S, ca)))
        if min(S[1:]) < X:
        	break
        ans = min(ans, S[0])

    if ans == float("inf"):
        ans = -1

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
N , M , X = list(map(int, input().split()))
C = []
for _ in range(N):
    C.append(list(map(int, input().split())))
ans = 10**9
for i in range(2**N):
    i_bin = (bin(i)[2:]).zfill(N)
    flag = True
    for j in range(M):
        tot = sum([ int(i_bin[k])* C[k][j] for k in range(N)])
        if tot < X:
            flag = False
    am = sum([ int(i_bin[k]) * C[k][0] for k in range(N)])
    if flag and am<ans:
        ans = am
if ans == 10**9:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
[N, M, X] = [int(i) for i in input().split()]
bk = [[int(i) for i in input().split()] for _ in range(N)]

ans = 12*10**5
for seq in product(range(2), repeat=N):
    S = [0]*(M+1)
    for i in range(N):
       for j in range(M+1):
           S[j] += seq[i]*bk[i][j]     
    if min(S[1:M+1]) >= X:
        ans = min(ans, S[0]) 

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
[N, M, X] = [int(i) for i in input().split()]
bk = [[int(i) for i in input().split()] for _ in range(N)]

ans = 12*10**5
for seq in product(range(2), repeat=N):
    S = [0]*(M+1)
    for i in range(N):
       for j in range(M+1):
           S[j] += seq[i]*bk[i][j]
    print(S, seq)       
    if min(S[1:M+1]) >= X:
        ans = min(ans, S[0]) 

print(ans)

Submission status: Wrong Answer

Solution code:
def check(understanding,X):
    for individual in understanding:
        if individual < X:
            return False
    return True

cost=0
inputs1 =list(map(int, input().split()[:3]))
N=inputs1[0]
M=inputs1[1]
X=inputs1[2]

matrix=[]
understanding= list(range(M))
for i in range(N):
    inputs =list(map(int, input().split()[:M+1]))
    matrix.append(inputs)

for i in range(N):
    cost+=matrix[i][0]
    for j in range(1,M+1):
        understanding[j-1]+=matrix[i][j]
    if check(understanding,X):
        print(cost)
        break

if not check(understanding,X):
    print(-1)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
c = list(list(map(int,input().split())) for _ in range(n))
ans = float("inf")
for i in range(1<<n):
    mokuhyo = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            for r in range(m):
                mokuhyo[r] += c[j][r+1]
            cost += c[j][0]
    for k in mokuhyo:
        if k < x:
            break
        else:
            ans = min(ans, cost)
print("-1" if ans == float("inf") else ans)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
c = list(list(map(int,input().split())) for _ in range(n))
ans = 10**7
for i in range(1<<n):
    mokuhyo = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            for r in range(m):
                mokuhyo[r] += c[j][r+1]
            cost += c[j][0]
    for k in mokuhyo:
        if k < x:
            break
        else:
            ans = min(ans, cost)
print("-1" if ans == 10**7 else ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

cost = float("inf")
for i in range(2**N):
  tmp = np.array([0 for _ in range(M+1)])
  for j in range(N):
    if (i>>j) & 1:
      tmp += np.array(C[j])
  if min(tmp[1:]) >= 10:
    cost = min(cost, tmp[0])

print(-1 if cost == float("inf") else cost)

Submission status: Wrong Answer

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

ans = 10 ** 7

for i in range(2 ** n):
    flag = format(i, "b")
    flag = "0" * (n - len(flag)) + flag
    tmp = 0
    check = [0] * (m)

    for j in range(n):
        if flag[j] == "0":
            continue
        tmp += arr[j][0]
        for k in range(m):
            check[k] += arr[j][k + 1]

    for j in range(m):
        if check[j] < x:
            break
        else:
            ans = min(ans, tmp)

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

Submission status: Wrong Answer

Solution code:
from itertools import product
n,m,x = list(map(int, input().split()))
book = []
for i in range(n):
  book.append(list(map(int, input().split())))
ans = 10 ** 5 * n
for i in product([0,1], repeat=n):
  price = 0
  skill = [0] * m
  for index_, bit in enumerate(i):
    if bit:
      for j in range(m):
        skill[j] += book[index_][ j + 1]
      price += book[index_][0]
  if all(v >= x for v in skill):
    ans = min(ans, price)
        
print(ans)

Submission status: Wrong Answer

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

ans = -1
for i in range((1<<N)-1):
    u = [0] * M
    p = 0
    for j in range(N):
        if i & (1 << j):
            p += C[j]
            for k in range(M):
                u[k] += A[j][k]
    if min(u) >= X:
        if ans == -1 or ans > p:
            ans = p
print(ans)

Submission status: Wrong Answer

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

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

# print(array)
# print(n)
ans = 10 ** 8
for i in range(2**n):
    price = 0
    skill = [0] * m

    for k in range(n):
        if (i >> k) & 1:
            price += array[k][0]
            for j in range(m):
                skill[j] += array[k][j+1]
    for l in range(m):
        if skill[l] < x:
            break
        else:
            ans = min(ans, price)


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

Submission status: Wrong Answer

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

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

# print(array)
# print(n)
ans = 10 ** 18
for i in range(2**n):
    price = 0
    skill = [0] * m

    for k in range(n):
        if (i >> k) & 1:
            price += array[k][0]
            for j in range(m):
                skill[j] += array[k][j+1]
    for l in range(m):
        if skill[l] < x:
            break
        else:
            ans = min(ans, price)


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

Submission status: Wrong Answer

Solution code:
N,M,X = map(int,input().split())
array = [ list(map(int,input().split())) for _ in range(N) ]
price = 10**18
for i in range ( 2**N ):
  collect = 0
  skill = [0]*M
  for k in range(N):
    if ( i >> k ) & 1:
      collect += array[k][0]
      for j in range (M):
        skill[j] += array[k][j+1]
  for t in range(M):
    if skill[t] < X:
      break
    else:
      price = min(price,collect)
      
print( -1 if price == 10**18 else price)

Submission status: Wrong Answer

Solution code:

def main():
    n, m, x = map(int, input().split(" "))
    ca =[]
    a = []
    c = []
    ans = 1e6
    for i in range(n):
        ca.append(list(map(int, input().split(" "))))
    for i in range(n):
        c.append(ca[i][0])
        a.append(ca[i][1:])
    for i in range(1<<n):
        a_sum = [0]*m
        c_sum = 0
        for j in range(n):
            if i >> j & 1 == 1:
                for k in range(m):
                    a_sum[k] += a[j][k]
                c_sum += c[j]
        if min(a_sum) >= x and c_sum < ans:
            ans = c_sum
    if ans == 1e6:
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n, m, x = map(int, input().split(" "))
    ca =[]
    for i in range(n):
        ca.append(list(map(int, input().split(" "))))
    min_c = 1e6
    for i in range(1<<n):
        a = [0]*(m)
        c = 0
        for j in range(n):
            if i >> j & 1 ==1:
                for k in range(1,m+1):
                    a[k-1] += ca[j][k]
                c += ca[j][0]
        if min(a) >= x and c <min_c:
            min_c = c
    if min_c == 1e6: print(-1)
    else:print(min_c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = float("inf")
lst1 = [i for i in range(n)]
for i in range(2**n):
    books = [0 for i in range(n)]
    lst2 = []
    memo = []
    for j in range(n):
        if (i>>j)&1 == 1:
            num = lst1[j]
            lst2.append(num)
            books = [x+y for (x,y) in zip(books,CA[num])]
    if all([i >= x for i in books[1:n]]):
        if ans > books[0]:
            ans = books[0]
            memo = lst2
if ans == float("inf") or memo == False:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

ans = float("inf")
lst1 = [i for i in range(n)]
for i in range(2**n):
    books = [0 for i in range(n)]
    lst2 = []
    memo = []
    for j in range(n):
        if (i>>j)&1 == 1:
            num = lst1[j]
            lst2.append(num)
            books = [x+y for (x,y) in zip(books,CA[num])]
    if all([i >= x for i in books[1:n]]):
        if ans > books[0]:
            ans = books[0]
            memo = lst2
if ans == float("inf") or memo == []:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

ans = float("inf")
lst1 = [i for i in range(n)]
for i in range(2**n):
    books = [0 for i in range(n)]
    for j in range(n):
        if (i>>j)&1 == 1:
            num = lst1[j]
            books = [x+y for (x,y) in zip(books,CA[num])]
    if all([i >= x for i in books[1:n]]):
        if ans > books[0]:
            ans = books[0]
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

ans = float("inf")
lst1 = [i for i in range(n)]
for i in range(2**n):
    books = [0 for i in range(n)]
    for j in range(n):
        if (i>>j)&1 == 1:
            num = lst1[j]
            books = [x+y for (x,y) in zip(books,CA[num])]
    if all([i >= x for i in books[1:m]]):
        if ans > books[0]:
            ans = books[0]
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

ans = float("inf")
lst1 = [i for i in range(n)]
for i in range(2**n):
    books = [0 for i in range(n)]
    for j in range(n):
        if (i>>j)&1 == 1:
            num = lst1[j]
            books = [x+y for (x,y) in zip(books,CA[num])]
    if all(i >= x for i in books[1:m]):
        if ans > books[0]:
            ans = books[0]
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

ans = float("inf")
lst1 = [i for i in range(n)]
for i in range(2**n):
    books = [0 for i in range(n)]
    for j in range(n):
        if (i>>j)&1 == 1:
            num = lst1[j]
            books = [x+y for (x,y) in zip(books,CA[num])]
    if all(i >= x for i in books[1:n]):
        if ans > books[0]:
            ans = books[0]
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N,M,X = map(int, input().split())
A = []
C = []
for i in range(N) :
    I = list(map(int,input().split()))
    C.append(I[0])
    A.append(I[1:])

ans = 10**12
for iv in range(1 << N) :
    r = [0] * M
    c = 0
    isOk = True
    for i in range(N) :
        if(not iv >> i & 1) :
            continue
        c += C[i]
        for j in range(M) :
            r[j] += A[i][j]
    for i in range(M) :
        if(r[i] < X) :
            isOk = False
    if(isOk) :
        ans = min(ans,c)
if(ans == 10**6) :
    ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,X = map(int, input().split())
A = []
C = []
for i in range(N) :
    I = list(map(int,input().split()))
    C.append(I[0])
    A.append(I[1:])

ans = 10**6
for iv in range(1 << N) :
    r = [0] * M
    c = 0
    isOk = True
    for i in range(N) :
        if(not iv >> i & 1) :
            continue
        c += C[i]
        for j in range(M) :
            r[j] += A[i][j]
    for i in range(M) :
        if(r[i] < X) :
            isOk = False
    if(isOk) :
        ans = min(ans,c)
if(ans == 10**6) :
    ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M, X = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L = sorted(L, key=lambda x: x[0], reverse=True)
tmp = np.sum(np.array(L), axis=0)
ans = tmp[0]
i = 0
cnt = 0
for i in range(N):
    if all([x >= X for x in (tmp-L[i])[1:]]):
        ans -= L[i][0]
        cnt += 1
        tmp = tmp - L[i]

ans = -1 if cnt == 0 else ans
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import sub, add
import sys
N, M, X = map(int, input().split())
AC = []
for _ in range(N):
    AC.append(list(map(int, input().split())))

S = [sum(x) for x in zip(*AC)]
s = [sum(x) for x in zip(*AC)]
for m in range(1, M+1):
    if s[m] < X:
        print(-1)
        sys.exit(0)
        
AC.sort(reverse=True)        
for n in range(N):
    ac = AC[n]
    s = list(map(sub, s, ac))
    for m in range(1, M+1):
        if s[m] < X:
            s = list(map(add, s, ac))
            break
            
print(min(S[0], s[0]))

Submission status: Wrong Answer

Solution code:
from operator import sub, add
import sys
N, M, X = map(int, input().split())
AC = []
for _ in range(N):
    AC.append(list(map(int, input().split())))

s = [sum(x) for x in zip(*AC)]

for m in range(1, M+1):
    if s[m] < X:
        print(-1)
        sys.exit(0)
        
#AC.sort(reverse=True)        
for n in range(N):
    ac = AC[n]
    s = list(map(sub, s, ac))
    for m in range(1, M+1):
        if s[m] < X:
            s = list(map(add, s, ac))
            break
            
print(s[0])

Submission status: Wrong Answer

Solution code:
from operator import sub, add
import sys
N, M, X = map(int, input().split())
AC = []
for _ in range(N):
    AC.append(list(map(int, input().split())))

s = [sum(x) for x in zip(*AC)]

for m in range(1, M+1):
    if s[m] < X:
        print(-1)
        sys.exit(0)
        
AC.sort(reverse=True)        
for n in range(N):
    ac = AC[n]
    s = list(map(sub, s, ac))
    for m in range(1, M+1):
        if s[m] < X:
            s = list(map(add, s, ac))
            break
            
print(s[0])

Submission status: Wrong Answer

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

ans = 12*10**5
for i in range(2**n):
    s = [0]*(m+1)
    for j in range(n):
        if (i>>j) & 1 == 1:
            for k in range(m+1):
                s[k] += ca[j][k]
    for j in range(1, m+1):
        if s[j] < x:
            break
    else:
        ans = min(ans, s[0])
print(-1 if ans == 12*10**5 else ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
table = []
ret = float('inf')
N, M, X = map(int, input().split())
for _ in range(N):
    table.append(list(map(int, input().split())))

# print(table)

# N 桁の2進数とか全列挙したい（状態全探索とか）
for a in product(range(2), repeat = N):
    # print(a)
    algo = [0] * M
    cost = 0
    for i in range(N):
        # print(a[i])
        if a[i] == 0: continue
        cost += table[i][0]
        for j in range(M):
            algo[j] += table[i][j + 1]
    is_satisfied = True
    for i in range(M):
        if algo[i] < X: is_satisfied = False
        break
    if is_satisfied:
        ret = min(ret, cost)

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

Submission status: Wrong Answer

Solution code:
from itertools import product
table = []
ret = float('inf')
N, M, X = map(int, input().split())
for _ in range(N):
    table.append(list(map(int, input().split())))

# print(table)

# N 桁の2進数とか全列挙したい（状態全探索とか）
for a in product(range(2), repeat = N):
    # print(a)
    algo = [0] * M
    cost = 0
    for i in range(N):
        # print(a[i])
        if not a[i]: continue
        cost += table[i][0]
        for j in range(M):
            algo[j] += table[i][j + 1]
    is_satisfied = True
    for i in range(M):
        if algo[i] < X: is_satisfied = False
        break
    if is_satisfied:
        ret = min(ret, cost)

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

Submission status: Wrong Answer

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

cost=2*10**6
for i in range(2**n) :    #参考書の買う場合の数
    cost1=0
    B=[[] for i in range(m)]
    for j in range(n) :   #どの本を買うか
        if ((i>>j)&1) :
            cost1+=A[j][0]
            for k in range(1,m+1) :
                B[k-1].append(A[j][k])

    for k in range(m) :
        if x<=sum(B[k]) :
            continue
        else :
            break
    else :
        cost=min(cost,cost1)
            

print(cost)

Submission status: Wrong Answer

Solution code:
from itertools import product
table = []
ret = float('inf')
N, M, X = map(int, input().split())
for _ in range(N):
    table.append(list(map(int, input().split())))

# N 桁の2進数とか全列挙したい（状態全探索とか）
for a in product(range(2), repeat = N):
    algo = [0] * M
    cost = 0
    for i in range(N):
        if not a[i]: continue
        cost += table[i][0]
        for j in range(M):
            algo[j] += table[i][j + 1]
    is_satisfied = True
    for i in range(M):
        if algo[i] < X: is_satisfied = False
        break
    if is_satisfied:
        ret = min(ret, cost)

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

Submission status: Wrong Answer

Solution code:
from itertools import product
table = []
ret = float('inf')
N, M, X = map(int, input().split())
for _ in range(N):
    table.append(list(map(int, input().split())))

# N 桁の2進数とか全列挙したい（状態全探索とか）
for a in product(range(2), repeat = N):
    algo = [0] * M
    cost = 0
    for i in range(N):
        if a[i]: continue
        cost += table[i][0]
        for j in range(M):
            algo[j] += table[i][j + 1]
    is_satisfied = True
    for i in range(M):
        if algo[i] < X: is_satisfied = False
        break
    if is_satisfied:
        ret = min(ret, cost)

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def find_good( list , x ):
    #if ok : return 1 , not ok : return 0
    flag = 1
    for i in list:
        if i < x:
            flag = 0
            break
    return flag


def main():
    n,m,x = map( int , input().split() )
    a = []
    c = []
    for i in range(n):
        I = list( map( int , input().split() ) )
        c.append( I[0] )
        a.append( I[1:] )
    
    ans_min = sum(c)

    flag_ = 0

    #print(a)

    for i in range( 2 ** n ):
        z = i
        book_i = 0
        ans_list = [ 0 for j in range(m) ]
        ans_cost = 0

        while( z != 0 ):
            y = z % 2

            z = z // 2

            if y:
                for j in range( m ):
                    ans_list[j] += a[book_i][j]
                ans_cost += c[book_i]
            book_i += 1
        

        if find_good( ans_list , x ) and ans_min > ans_cost:
            ans_min = ans_cost
            flag_ = 1
    
    if flag_:
        print(ans_min)
    else:
        print(-1)
    







main()

Submission status: Wrong Answer

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

ans = 10**9 + 10

for i in range(N**2):
    money = 0
    L = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            money += A[j][0]
            for k in range(M):
                L[k] += A[j][k+1]
    if min(L) >= X and money < ans:
        ans = money

if ans == 10**9 + 10:
    ans = -1

print(ans)