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: Accepted

Solution code:
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]
answer = 10**7

for num in range(2**N):
  algos = [0 for i in range(M+1)]
  money = 0
  for i in range(N):
    if num>>i&1:
      for j in range(1, M+1):
        algos[j] += books[i][j]
      money += books[i][0]
  master = True
  for k in range(1, M+1):
    if algos[k] < X:
        master = False
        break
  if master:
    answer = min(answer, money)
if answer == 10**7:
  print(-1)
else:
  print(answer)

Submission status: Accepted

Solution code:
import numpy as np
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(np.array(l[1:]))
ans = 10**100
for i in range(2**N):
    rikaido = np.zeros(M)
    c = 0
    for j in range(N):
        if (i >> j) & 1:
            c += C[j]
            rikaido += A[j]
    if all([x >= X for x in rikaido]):
        ans = min(ans, c)
print(ans if ans != 10**100 else -1)

Submission status: Accepted

Solution code:
from itertools import product

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

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

ans = 10**12+1
for t in product([0,1], repeat=n): # (1, 0, 0)
    cost = 0
    understanding = [0] * m
    for i, b in enumerate(t):
        if b == 1:
            cost += CA[i][0]
            for j, a in enumerate(CA[i][1:]):
                understanding[j] += a  
    if sum(True for u in understanding if u >= x) == m:
        ans = min(ans, cost)

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

Submission status: Accepted

Solution code:

def main():
    n, m, x = map(int, input().split(" "))
    ca =[]
    a = []
    c = []
    INF = 1e7
    ans = INF
    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 == INF:
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
    n, m, x = map(int, input().split(" "))
    ca =[]
    a = []
    c = []
    ans = 1e9
    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 == 1e9:
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

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**12) :
    ans = -1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,M,X=map(int,input().split())
allList=[]
for _ in range(N):
    allList.append(np.array(list(map(int,input().split()))))
minnum=10**7
for i in range(2**N):
    skill=[0]*(M+1)
    flag=True
    for row in range(N):
        if i&(2**row)>0:
            skill+=allList[row]
    for j in range(M):
        if skill[j+1]<X:
            flag=False
    if flag:
        minnum=min(minnum,skill[0])
if minnum==10**7:
    minnum=-1
print(minnum)

Submission status: Accepted

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

flg = False
ans = 10**9
for i in range(2**N):
    bits = bin(i)[2:].zfill(N)
    ok = True
    xs = [0] * M
    tmp = 0
    for i, b in enumerate(bits):
        if b == '0': continue

        for j in range(M):
            xs[j] += L[i][j+1]

        tmp += L[i][0]

    for x in xs:
        if x < X:
            ok = False
            break

    if ok:
        flg = True
        ans = min(tmp, ans)

ans = ans if flg else -1
print(ans)

Submission status: Accepted

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

ans = -1
for i in range(n+1):
    for comb in combinations(range(n),i):
        a = [0 for _ in [0]*m]
        c = 0
        for j in comb:
            temp = t[j]
            c += temp[0]
            for k in range(m):
                a[k] += temp[k+1]
        flag = True
        for j in a:
            if j<x:
                flag = False
                break
        if flag:
            if ans==-1:
                ans = c 
            else:
                ans = min(ans,c)

print(ans)

Submission status: Accepted

Solution code:
n, m, x = map(int,input().split())
CA = [list(map(int, input().split())) for i in range(n)]
ch = [0]*m
res = 10**5*12 + 5
for i in range(2**n):
    money = 0
    ch = [0]*m
    for j in range(n):
        if ((i >> j) & 1):
            money += CA[j][0]
            for k in range(m):
                ch[k] += CA[j][k+1]
    if min(ch) >= x:
        res= min(money,res)
if res == 10**5*12 + 5:
    print(-1)
else:
    print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  3 21:04:57 2020

@author: liang
"""
from operator import add

#import numpy as np
N, M, X = map(int, input().split())

#A = [np.array(list(map(int, input().split()))[1:]) for _ in range(N)]
A = [list(map(int, input().split())) for _ in range(N)]
ans = 10**7
for i in range(2**N):
    C_list = list()
    for j in range(N):
        if i>>j&1 == 1:
            C_list.append(j)
    #tmp = np.array( [0]*M )
    tmp = [0]*(M+1)
    for i in C_list:
        tmp = list(map(add, A[i], tmp))
    if all([ i >= X for i in tmp[1:]]) and tmp[0] < ans :
        ans = tmp[0]
    #print(tmp)
if ans == 10**7:
    ans = -1
print(ans)

Submission status: Accepted

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

ans = 12*10**6
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**6 else ans)

Submission status: Accepted

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

#金額と理解度のリスト
money = []
skill = []
for i in range(n) :
    a = []
    a = (list(map(int, input().split())))
    money.append(a[0])
    skill.append(a[1:])

#本の購入パターン
l_list = []
for j in range(2 ** n) :
    l = []
    for k in range(n) :
        if (j >> k) & 1 :
            l.append(1)
        else:
            l.append(0)
        
    l_list.append(l)

#金額と理解度の合計のリスト
ans = -1
min_money_sum = sum(money)
for o in l_list :
    ability = [0 for s in range(m)]
    money_sum = 0
    for p in range(n) :
        if o[p] == 1 :
            ability = [q + r for (q, r) in zip(ability, skill[p])]
            money_sum += money[p]
    
    cnt = 0 
    for t in range(m) :
        if ability[t] < x :
            cnt += 1
    
    if cnt == 0 :
        min_money_sum = min(min_money_sum, money_sum)
        ans = 0

#最小額
if ans != -1 :
    print(min_money_sum)
else:
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, M, X = map(int,input().split())
C = []
A = []
for i in range(N):
    c = 0
    a = []
    c, *a = map(int,input().split())
    C.append(c)
    A.append(a)
inf = float("inf")
res = inf
for bit in range(1 << N):
    Cost = 0
    Wise = [0] * M
    for i in range(N):
        if (bit >> i) & 1:# i冊目を買うときの処理
            Cost += C[i]
            for j, a in enumerate(A[i]):
                Wise[j] += a
            #else:# i冊目を買わないときの処理（今回は何もしないので省略）
    if min(Wise) >= X and Cost <= res:
        res = Cost
if res == inf:
    print("-1")
else:
    print(res)

Submission status: Accepted

Solution code:
import numpy as np
N, M, X = map(int,input().split())
C = []
A = []
for i in range(N):
    c = 0
    a = []
    c, *a = map(int,input().split())
    C.append(c)
    A.append(a)
A = np.array(A)
inf = float("inf")
res = inf
for bit in range(1 << N):
    Cost = 0
    Wise = np.zeros(M)
    for i in range(N):
        if (bit >> i) & 1:# i冊目を買うときの処理
            Cost += C[i]
            Wise += A[i]
            Wise = Wise.tolist()
            #else:# i冊目を買わないときの処理（今回は何もしないので省略）
    if min(Wise) >= X and Cost <= res:
        res = Cost
if res == inf:
    print("-1")
else:
    print(res)







"""
n,m,x = map(int,input().split())
c=[]
a=[]
INF = float("inf")
stock = INF
for _  in range(n):
    c_temp,*a_temp = list(map(int,input().split()))
    c.append(c_temp)
    a.append(a_temp)

#すべての組み合わせを計算

for bit in range(1 << n):
    cost_total = 0
    smart_total = [0]*m
    #１セットごとの処理
    for i in range(n):
        #一冊ごとの処理
        if (bit >> i) & 1:
            # i冊目を買うときの処理
            smart = []
            cost_total += c[i]
            smart = a[i]
            for j , sm in enumerate(smart):
                smart_total[j] += sm
        #else:
            # i冊目を買わないときの処理（今回は何もしないので省略）
    judege = True
    for i in range(m):
        if smart_total[i] < x:
            judege = False
    if judege:
        stock = min(cost_total,stock)
if stock == INF:
    print("-1")
else:
    print(stock)"""

Submission status: Accepted

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
count=0
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 :
            count+=1
            break
    else :
        cost=min(cost,cost1)
            
if count==2**n :
    print(-1)
else :
    print(cost)

Submission status: Accepted

Solution code:
n,m, x = map(int,input().split())
text=[]
buy=10**10
for i in range(n):
  text.append(list(map(int,input().split())))
for i in range(2**n):
  bag=[0]*(m+1)
  
  for j in range(n):#いれる過程
    if ((i>>j)&1):#j冊目のフラグがあれば
      for k in range(m+1):
        bag[k]+= text[j][k]#bagにいれる
  
  if min(bag[1:])>=x and bag[0]<buy:
    buy=bag[0]

if buy==10**10:
  buy=-1
print(buy)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np


def solve(N, M, X, C, A):
    answer = float("inf")
    for ptn in range(1, 1 << len(C)):
        buy = [ptn & 1 << i == 1 << i for i in range(len(C))]
        if (A[buy].sum(axis=0).min() >= X) and (
            C[buy].sum() < answer
        ):
            answer = C[buy].sum()

    if answer == float("inf"):
        return -1

    return answer


def main():
    N, M, X = map(int, input().split())
    C = [None for _ in range(N)]
    A = [None for _ in range(N)]
    for i in range(N):
        C[i], *A[i] = map(int, input().split())
    C = np.array(C, dtype=np.uint32)
    A = np.array(A, dtype=np.uint32)
    answer = solve(N, M, X, C, A)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np


# 参考書の組が理解度を充足しているか
def ok(X, A):
    pass


def solve(N, M, X, C, A):
    answer = float("inf")
    for ptn in range(1, 2 ** len(C)):
        buy = [ptn & 2 ** i == 2 ** i for i in range(len(C))]
        if (A[buy].sum(axis=0).min() >= X) and (
            C[buy].sum() < answer
        ):
            answer = C[buy].sum()

    if answer == float("inf"):
        return -1

    return answer


def main():
    N, M, X = map(int, input().split())
    C = [None for _ in range(N)]
    A = [None for _ in range(N)]
    for i in range(N):
        C[i], *A[i] = map(int, input().split())
    C = np.array(C, dtype=np.uint32)
    A = np.array(A, dtype=np.uint32)
    answer = solve(N, M, X, C, A)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
N,M,X = map(int,input().split())
L = [i for i in range(0,2)]
c_list = list(itertools.product(L, repeat=N)) #重複あり組み合わせ
Alg = []
for i in range(N):
    Alg.append(list(map(int,input().split())))
Ans = 1<<50
Money = 0
def judge(per):
    Money = 0
    tryAlg = [0]*M
    for i in range(len(per)):
        if per[i] == 1:
            Money += Alg[i][0]
            for j in range(1,M+1):
                tryAlg[j-1] += Alg[i][j]
    for m in tryAlg:
        if m < X:
            Money = -1
            break
    return Money
for per in c_list:
    An = judge(per)
    if An != -1:
        Ans  = min(An,Ans)
if Ans == 1<<50:
    Ans = -1
print(Ans)

Submission status: Accepted

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: Accepted

Solution code:
n, m, x = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(n):
    a[i] = list(map(int, input().split()))
ans = 10000000000000
for i in range(2 ** n):
    money = 0
    understand = [0] * m
    for j in range(n):
        if i >> j & 1:
            money += a[j][0]
            for k in range(1, m + 1):
                understand[k - 1] += a[j][k]
    if min(understand) >= x:
        ans = min(money, ans)
print(ans if ans < 10000000000000 else -1)

Submission status: Accepted

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(1, 2**N):
    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)

Submission status: Accepted

Solution code:
inf = int(9e18)


def recursive(i, total, cost, C, A, X):
    if i == len(A):
        return inf
    ncost = recursive(i+1, total, cost, C, A, X)

    ok = True
    for j in (range(len(total))):
        total[j] += A[i][j]
        if (total[j] < X):
            ok = False
    if ok:
        dcost = cost + C[i]
    else:
        dcost = recursive(i+1, total, cost + C[i], C, A, X)
    for j in (range(len(total))):
        total[j] -= A[i][j]

    return (min(ncost, dcost))


def main():
    nmx = [int(_x) for _x in input().split()]
    n = nmx[0]
    m = nmx[1]
    x = nmx[2]
    c = []
    a = []
    for i in range(n):
        ca = [int(_x) for _x in input().split()]
        c.append(ca[0])
        a.append(ca[1:])
    total = [0] * m

    result = recursive(0, total, 0, c, a, x)

    if result == inf:
        print(-1)
    else:
        print(result)


main()

Submission status: Accepted

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

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

ans = 10**11
for i in range(2**N):
    b = format(i, "0" + str(N) + "b")
    r = [0] * M
    c = 0
    for j in range(N):
        f = int(b[j])
        c += C[j] * f
        for k in range(M):
            r[k] += f * A[j][k]
        if min(r) >= X:
            ans = min(c, ans)

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

Submission status: Accepted

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

sum_money = float("inf")
for i in range(2 ** N):
  money = 0
  algorithm = [0]*M
  for j in range(N):
    if (i >> j) & 1 == 1:
      money += CA[j][0]
      for k in range(M):
        algorithm[k] += CA[j][k+1]
  check = True
  for l in algorithm:
    if l < X:
      check = False
  if check:
    sum_money = min(sum_money, money)
    
print(sum_money if sum_money != float("inf") else -1)

Submission status: Accepted

Solution code:
import numpy as np

n, m, x = map(int, input().split())
data = []
for i in range(n):
    temp = list(map(int, input().split()))
    data.append(temp)
# ------------------------
# 今回の場合は、MとNが異様に小さいので、全探索して、Xを超える条件をMinで取るのがBetter
cost = 10 ** 17


# 0の場合は全部がOFFなので、はじく。
for bit in range(1, 2 ** n):
    # print(bit)
    ttt = np.zeros(m + 1)

    for j in range(n):
        # onの場合
        if (bit >> j & 1):
            #print('OK!', j)
            tar = np.array(data[j])
            ttt += tar

    check = np.where(ttt[1:] >= x)[0]
    if (len(check) == m):
        cost = min(cost, ttt[0])
    else:
        pass

if (cost == 10 ** 17):
    print(-1)
else:
    print(int(cost))

Submission status: Accepted

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

INF = 30
ans = 1 << INF

data = []
for i in range(N):
    c = list(map(int, input().split()))
    data.append(c)

for i in range(1, 2**N):
    tmp = 0
    skill = [0] * M
    for j in range(N):
        if i >> j & 1:
            tmp += data[j][0]
            for k in range(M):
                skill[k] += data[j][k + 1]
    if min(skill) >= X and tmp < ans:
        ans = tmp

if ans == 1 << INF:
    print('-1')
else:
    print(ans)

Submission status: Accepted

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

books=[]

for i in range(n):
    books.append([int(i) for i in input().split()])


# ==================================================-
# 整数を２進数に変換
def get_conbination(i,length):
    return format(i, '#0'+str(length+2)+'b')[2:]

min_cost=100000000000000
for i in range(2**n):
    rikai=[0]*m
    select=get_conbination(i,n)
    cost=0
    for j in range(n):
        if select[j] == "1":
            for k in range(m):
                rikai[k]+=books[j][k+1]
            cost+=books[j][0]
    if min(rikai)>=x:
        min_cost=min(min_cost,cost)

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

Submission status: Accepted

Solution code:
def resolve():
    N, M, X = list(map(int, input().split()))
    C = []
    A = []
    for i in range(N):
        ins = list(map(int, input().split()))
        C.append(ins[0])
        A.append(ins[1:])
    minprice = float("inf")
    for bits in range(1<<N):
        comps = [0 for _ in range(M)]
        price = 0
        for odr in range(N):
            if (bits & (1<<odr)):
                price += C[odr]
                for i in range(M):
                    comps[i] += A[odr][i]
        for i in range(M):
            if comps[i] < X:
                break
        else:
            minprice = min(minprice, price)
    print(minprice if minprice < float("inf") else -1)


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
cc=[list(map(int,input().split())) for _ in range(n)]
ans=float('inf')
for b in range(1<<n):
    a=[0]*(m+1)
    for i in range(n):
        if b&(1<<i)==0:
            continue
        for k,l in enumerate(cc[i]):
            a[k]+=l
        if min(a[1:])>=x:
            ans=min(ans,a[0])
    a=[0]*(m+1)
if ans==float('inf'):
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

N_book, M_algo, X_skill = map(int, input().split())  

A = []
for _ in range(N_book):
    a = list(map(int, input().split()))
    A.append(a)

flg = False
ans = float('inf')
for selector in list(itertools.product([1, 0], repeat=N_book))[:-1]:
    C = []
    for i in range(N_book):
        if selector[i] == 1:
            C.append(A[i])
    
    D = list(np.array(C).sum(axis=0))
    if (False in [i >= X_skill for i in D[1:]]):
        continue
    else:
        flg = True
        ans = min(ans, D[0])

if flg:
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

cost = (10 ** 5) * 12

for i in range(2 ** N):
  total, a = 0, [0] * M
  for j in range(N):
    if i >> j & 1:
      total += CA[j][0]
      for k in range(M): a[k] += CA[j][k + 1]
  for j in range(M):
    if a[j] < X:
      if i == 2 ** N - 1: cost = -1
      break
  else: cost = min(cost, total)

print(cost)

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
ls = []
for i in range(n):
  ls.append(list(map(int,input().split())))
minimum = 10**12
for i in range(2**n+1):
  f = "{{:0{}b}}".format(n)
  now = f.format(i)
  understand = [0] * m
  cost = 0
  for j in range(len(now)):
    if now[j] == "1":
      cost += ls[j][0]
      for k in range(m):
        understand[k] += ls[j][k+1]
  if cost < minimum:
    if min(understand) >= x:
      minimum = cost
if minimum == 10**12:
  print(-1)
else:
  print(minimum)

Submission status: Accepted

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

c = []
for i in range(n):
    c.append(a[i][0])
    a[i].pop(0)

ans = 1000000000

# bit全探索
for i in range(1 << n):
    score = [0] * m
    tmp = 0
    for j in range(n):
        if (i >> j) % 2 == 1:
            tmp += c[j]
            for k in range(m):
                score[k] += a[j][k]

    if min(score) >= x:
        ans = min(ans , tmp)

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

Submission status: Accepted

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

c = []
for i in range(n):
    c.append(a[i][0])
    a[i].pop(0)

ans = 1000000000

for i in range(1 << n):
    score = [0] * m
    tmp = 0
    for j in range(n):
        if (i >> j) % 2 == 1:
            tmp += c[j]
            for k in range(m):
                score[k] += a[j][k]

    check = True
    for l in range (m):
        if score[l] < x:
            check = False

    if check:
        ans = min(ans , tmp)

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
C = [(list(map(int, input().split()))) for _ in range(N)]
 
# bit全探索を行い、参考書に関する全ての組みについて、値段と理解度を求める
ans = 10**10
for i in range(2**N):
  U = [0]*(M+1)
  for j in range(N):
    if ((i >> j) & 1):
      for k in range(M+1):
        U[k] += C[j][k]
  
  # ある組みが条件を満たし、その値段が現時点で最小なら、更新する
  if sum([u >= X for u in U[1:]]) == M:
    ans = min(ans, U[0])

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
C = [(list(map(int, input().split()))) for _ in range(N)]
 
# bit全探索を行い、参考書に関する全ての組みについて、値段と理解度を求める
ans = 10**10
for i in range(2**N):
  U = [0]*(M+1)
  for j in range(N):
    if ((i >> j) & 1):
      for k in range(M+1):
        U[k] += C[j][k]
  
  # ある組みが条件を満たすなら、その値段をvalに追加
  if sum([u >= X for u in U[1:]]) == M:
    ans = min(ans, U[0])

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

Submission status: Accepted

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

# bit全探索を行い、参考書に関する全ての組みについて、値段と理解度を求める
val = []
for i in range(2**N):
  U = [0]*(M+1)
  for j in range(N):
    if ((i >> j) & 1):
      for k in range(M+1):
        U[k] += C[j][k]
  
  # ある組みが条件を満たすなら、その値段をvalに追加
  if sum([u >= X for u in U[1:]]) == M:
    val.append(U[0])

# 条件を満たす組みの中で、値段が最小のものを出力し、組みが無ければ-1を出力する
ans = 0
if len(val) == 0: ans = -1
else: ans = min(val)
print(ans)

Submission status: Accepted

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

#print(n, m, x, a)

#0b00・・・０~0b111・・・１を全部作成
cost_abl = []
cost_lis = []
abl_lis = []
for i in range(1 << n):
    cost = 0
    abl_sum = [0] * m
    #print(abl_sum)
    #abl_1, abl_2, abl_3 = 0, 0 ,0
    for j in range (len(a)):
        mask = 1 << j
        if i & mask:
            cost += a[j][0]
            for k in range(m):
                abl_sum[k] += a[j][k + 1]
            # abl_1 +=  a[j][1]
            # abl_2 += a[j][2]
            # abl_3 += a[j][3]
    cost_lis.append(cost)
    abl_lis.append(abl_sum)
    #print(bin(i))
#print(cost_lis, abl_lis)

cost_new_lis = []
for i in range(len(abl_lis)):
    if min(abl_lis[i]) >= x:
        cost_new_lis.append(cost_lis[i])
    else:
        pass
#print(cost_new_lis)

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

Submission status: Accepted

Solution code:
def saiki(i,cost,score_list):
   if i == n:
       if min(score_list) >= x:
           ans.append(cost)
   else:
       temp = [score_list[j]+book_list[i][j+1] for j in range(m)]
       saiki(i+1,cost,score_list)
       saiki(i+1,cost+book_list[i][0],temp)

n,m,x = map(int,input().split())
book_list = [list(map(int, input().split())) for _ in range(n)]
ans=[]
saiki(0,0,[0]*m)
print(min(ans) if len(ans)!=0 else -1)

Submission status: Accepted

Solution code:

N, M, X = map(int, input().split(' '))
price, exp = [], [ [] for i in range(N) ]
rst = -1
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp[i] = ls[1:]
for i in range(1 << N):
    price_comb, exp_comb, exp_sum, cnt_ls = [], [], [0] * M, []
    for j in range (N):
        if i >> j & 1:
            price_comb.append(price[j])
            exp_comb.append(exp[j])
    for s in exp_comb:
        for t in range(M):
            exp_sum[t] += s[t]
    cnt_ls = [ x for x in exp_sum if x >= X ]
    if len(cnt_ls) == M:
        if rst == -1:
            rst = sum(price_comb)
        else:
            rst = min(rst, sum(price_comb))
print(rst)

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
books = [[] for _ in range(N)]
for i in range(N):
    books[i] = list(map(int, input().split()))
Inf = int(1e20)
ans = Inf
for i in range(2**N):
    a = [0 for _ in range(M+1)]
    for j in range(N):
        if (i & (1 << j)):
            a = [x+y for (x,y) in zip(a,books[j])]
    ok = True
    for k in range(M):
        if a[k+1] < X:
            ok = False
    if not ok:
        continue
    ans = min(ans, a[0])
if ans == Inf:
    ans = -1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
N,M,X=map(int,input().split())
A=[0]*N;cost=0;C=[0]*N;bit=0;v=[0]*M;f=0;minimum=100000*12+1;e=0
for i in range(N):
  a = deque(list(map(int, input().split())))
  C[i]=a[0]
  a.popleft()
  A[i]=a

#print(A[2][2])
#print(C)

for i in range(2**N):
  for j in range(N):
    bit=(1<<j)
    if (i & bit)>0:
      cost+=C[N-1-j]
      for k in range(M):
        v[k]=v[k]+A[N-1-j][k]
  for l in range(M):
    if v[l]<X:
      f=1
     
  if f!=1 and cost<minimum:
    minimum=cost
    e=i
  cost=0;v=[0]*M;f=0
            
print(minimum if minimum!=100000*12+1 else "-1")

Submission status: Accepted

Solution code:
import numpy as np

n,m,x = map(int,input().split())
ca = list(list(map(int,input().split())) for _ in range(n))

ans = 10**7
for i in range(1,2**n):
  l = []
  for j in range(n):
    if (i >> j) & 1:
      l.append(ca[j])
  s = np.sum(l,axis=0).tolist()
  if all(s[k] >= x for k in range(1,m+1)) and s[0] < ans:
    ans = s[0]

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

Submission status: Accepted

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

mn = 1e9
for i in range(2 ** N):
    p = [0] * M
    v = 0
    for j in range(N):
        if (1 << j) & i:
            v += C[j]
            for k in range(M):
                p[k] += A[j][k]
    if min(p) >= X:
        mn = min(mn, v)
print(mn if mn != 1e9 else -1)

Submission status: Accepted

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

min_sum_answer = -1
for i in range(2**n):
      min_sum = 0
      get_score = []
      for v in range(m):
         get_score.append(0)   
      for j in range(n):
            if (i >> j) & 1 ==1:
                  min_sum += c_a[j][0]
                  for l in range(m):
                        get_score[l] += c_a[j][l+1]
     
      #print(i)
      #print(min_sum)
      pre = 0 
      for s in range(m):
            if(get_score[s] < x):
                  pre = 1
                  break
      
      if pre == 0:
            if min_sum_answer == -1:
                  min_sum_answer = min_sum 
            elif min_sum_answer > min_sum:
                  min_sum_answer = min_sum 

if min_sum_answer == 0:
      print(-1)
else:
      print(min_sum_answer)