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:
import itertools
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
comb = []
for i in range(1, n+1):
    comb.append(list(itertools.combinations(c, i)))
ans = []
for i in range(len(comb)):
    for j in range(len(comb[i])):
        flag = True
        for l in range(1, m+1):
            sum = 0
            for k in range(len(comb[i][j])):
                sum += comb[i][j][k][l]
            if sum < x:
                flag = False
                break
        if flag:
            cos = 0
            for k in range(len(comb[i][j])):
                cos += comb[i][j][k][0]
            ans.append(cos)
if ans:
    print(min(ans))
else:
    print(-1)

Submission status: Accepted

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

num = pow(2, n)
min_cost = -1
for count in range(num):
    a_list = [0] * m
    cost = 0
    for i in range(n):
        bit = pow(2, i)
        if (count // bit) % 2 == 1:
            for j in range(m):
                a_list[j] = a_list[j] + list_ca[i][j + 1]
            cost += list_ca[i][0]
    if min(a_list) >= x:
        if min_cost == -1:
            min_cost = cost
        elif min_cost > cost:
            min_cost = cost

print(min_cost)

Submission status: Accepted

Solution code:
import itertools
def ans(n, m, x, list_all):
    for i in range(m):
        sum_m=0
        for j in range(n):
            sum_m+=list_all[j][i+1]
        if x>sum_m:
            return -1
    price=pow(10,7)
    for i in itertools.product([0,1], repeat=n):
        list=[0]*(m+1)
        boo=True
        for j in range(n):
            if i[j]==1:
                for k in range(m+1):
                    list[k]+=list_all[j][k]
        for j in range(m):
            if list[j+1]<x:
                boo=False
        if boo:
            if price>list[0]:
                price=list[0]
    return price


n, m, x =(int(x) for x in input().split())
list_all=[]
for i in range(n):
    li_i=list(map(int, input().split()))
    list_all.append(li_i)
print(ans(n, m, x, list_all))

Submission status: Accepted

Solution code:
B, A, R = map(int, input().split())

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

V = 100000000

for i in range(1, 2 ** B):
	bag = []
	choniki = [0]*A
	for j in range(B):
		check = 0  
		if ((i >> j) & 1):  
			bag.append(P[j][0])
			for k in range (0, A):
				choniki[k]+=P[j][k+1]
			for l in range (0, A):
				if choniki[l] < R:
					check = 1
			if check == 0 and sum(bag) < V:
				V = sum(bag)

if V < 100000000:
	print(V)
else:
	print(-1)

Submission status: Accepted

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

lst = []
for i in range(2**N):
    lst.append(str(bin(i)))
    lst[i] = lst[i][2:]
    lst[i] = lst[i].zfill(N)

lst_res = []

for j in lst:
    res = [0]*(M+1)
    for k in range(N):
        if j[k] == "0":
            pass
        else:
            res = [x+y for (x,y) in zip(res,S[k])]
    for l in range(1,M+1):
        if res[l] < X:
            break
    else:
        lst_res.append(res[0])

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

Submission status: Accepted

Solution code:
import itertools
import numpy as np
 
N, M, X = map(int, input().split())
c_list = []
for _ in range(N):
  c_list.append(list(map(int, input().split())))
  
cand = []
e_list = [i for i in range(N)]
for n in range(1, N+1):
  for e in itertools.combinations(e_list, n):
    sum_list = np.zeros(M)
    sum_maney = 0
    for i in set(e):
      sum_list += np.array(c_list[i][1:])
      sum_maney += c_list[i][0]
    flag = True
    for m in range(M):
      if not sum_list[m] >= X:
        flag = False
    if flag:
      cand.append(sum_maney)
if cand == []:
  print(-1)
else:
  print(min(cand))

Submission status: Accepted

Solution code:
import itertools
N, M, X = map(int, input().split())
C = []
for i in range(N):
    C.append(list(map(int, input().split())))
# C = sorted(C)
# num = []
ans = 10000000
rikai = [0] * M
num = [0, 1]
num_list = list(itertools.product(num, repeat=N))


for a in num_list:
    rikai = [0] * M
    kane = 0
    for i in range(N):
        if a[i] == 1:
            for j in range(1, M + 1):
                rikai[j - 1] = rikai[j - 1] + C[i][j]
            kane += C[i][0]
    if all(elem >= X for elem in rikai):
        ans = min(ans, kane)
if ans == 10000000:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n, m, x = map(int, input().split())
    ca = [list(map(int, input().split())) for i in range(n)]
    ans = float("inf")
    subsc = []  #選ばれている本
    for i in range(1 << n):
        for j in range(n):
            if (i >> j)&1:
                subsc.append(ca[j])
        flag = True
        cost = 0 #係る金額
        unst = 0 #各アルゴリズムの理解度
        if len(subsc) == 0:
            continue  
        for j in range(1,m+1):
            for k in range(len(subsc)):
                unst += subsc[k][j]
            if unst < x:
                flag = False #一つでもクリアできなければFalseになるはず
            unst = 0
        for j in range(len(subsc)):
            cost += subsc[j][0]
        if flag:
            ans = min(ans, cost)
        flag = True
        cost = 0
        subsc = []
    if ans == float("inf"):
        ans = -1
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
import itertools
n, m, x = map(int, input().split())
a = []
ans = 12 * 10**6
flg = False
for i in range(n):
    a.append([int(x) for x in input().split()])
for j in range(1, n+1):
    for z in itertools.combinations([y for y in range(1, n+1)], j):
        A = [0]*m
        M = [False]*m
        for k in range(m):
            C = 0
            for zz in z:
                C += a[zz-1][0]
                A[k] += a[zz-1][k+1]
                if A[k] >= x:
                    M[k] = True
            if False not in M:
                if ans > C:
                    ans = C
                    flg = True
if flg:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
from collections import defaultdict

n,m,x=map(int, input().split())
c=[]
tab=[]
cost = 10000000000
for i in range(n):
    A=[int(i) for i in input().split()]
    tab.append(A[1:])
    c.append(A[0])
for i in range(1<<n):
    tmp=0
    res = [0]*m
    for j in range(n):
        if(i&(1<<j)):
            tmp+=c[j]
            for k in range(m):
                res[k]+=tab[j][k]
    f=True
    for v in res:
        if v<x:
            f=False

    if f:
        cost = min(cost, tmp)



if cost!=10000000000:
    print(cost)
else:
    print(-1)

Submission status: Accepted

Solution code:
n, m, x = [int(i) for i in input().split()]
a = []
c = []
for i in range(n):
    inp = [int(i) for i in input().split()]
    c.append(inp[0])
    a.append(inp[1:])

ok = False
ans = float('inf')
for bit in range(1 << n):
    o = [0] * m
    tot = 0
    for i in range(n):
        if bit >> i & 1:
            tot += c[i]
            for j in range(m):
                o[j] += a[i][j]

    allOk = True
    for i in o:
        if i < x:
            allOk = False
            break
    if allOk:
        ok = True
        ans = min(ans, tot)

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

Submission status: Accepted

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


cost = [B[i][0] for i in range(N)]

flag = False
min_ = float('inf')
for i in range(1 << N):
    cost_temp = 0
    cnt = 0
    skills = [0] * M
    while i > 0:
        if (1 & i):
            cost_temp += cost[cnt]
            for m in range(M):
                skills[m] += B[cnt][m + 1]

        cnt += 1
        i >>= 1

    flag2 = False

    for m in skills:
        if m < X:
            flag2 = True
            break

    if not flag2:
        flag = True
        min_ = min(min_, cost_temp)

if flag:
    print(min_)
else:
    print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,X = inputMap()

	ans = 0
	inp = []
	for i in range(N):
		tmp = inputList()
		inp.append(tmp)

	ans = inf
	ans2 = ""
	for i in range(2**N):
		i_str = bin(i)
		i_str = i_str[2:]
		i_str = i_str[::-1]

		aaa = len(bin(2**N))-3 - len(i_str)
		for i in range(aaa):
			i_str += "0"

		#print(i_str)

		skills = [0 for i in range(M)]
		tmp = 0
		for j,val in enumerate(i_str):
			if val == "1":
				kk = inp[j]
				for ii,vol in enumerate(kk):
					if ii == 0:
						tmp += vol
					else:
						#if ii == 4 and i_str == "11111":
							#print(vol)
						skills[ii-1] += vol

		flg = True
		#print(skills)
		for vv in skills:
			if vv < X:
				flg = False
				break
		if flg == True:
			if ans > tmp:
				ans = tmp

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







#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import numpy as np
n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]

ans = np.inf
flag = 0
for i in range(2**n):
    r = np.array([0]*(m+1))
    for j in range(n):
        if (i>>j)&1:
            for k in range(m+1): r[k] += a[j][k]
    if np.all(r[1:]>=x):
        if ans > r[0]: ans = r[0]
        flag = 1
    else: flag = 0

if flag: print(ans)
else: print("-1")

Submission status: Accepted

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

import sys
import math
import itertools

debug = False

def log(text):
    if debug:
        print(text)


def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        (n, m, x) = [int(e) for e in lines[0].split(' ')]
        for _ in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        (n, m, x) = [int(e) for e in lines[0].split(' ')]

    ca_list = []
    for i in range(1, n+1):
        ca_list.append([int(e) for e in lines[i].split(' ')])
        
    return (n, m, x, ca_list)


def solve(n, m, x, ca_list):


    result = 100000 * n + 1
    for p in itertools.product([0,1], repeat=n):

        index_set = set([i for i, b in enumerate(p) if b == 1])
        ca_list_tmp = [e for i, e in enumerate(ca_list) if i in index_set]

        if debug:
            log("index_set=%s" % index_set)
            log("ca_list_tmp=%s" % ca_list_tmp)
        
        total_c = 0
        total_a = [0 for _ in range(m)]
        r = True 
        for ca in ca_list_tmp:
            total_c = total_c + ca[0]

            for i in range(1, m + 1):
                total_a[i-1] = total_a[i-1] + ca[i]

        for i in range(m):
            if total_a[i] < x:
                r = False
                break
            
        if r:
            if total_c < result:
                result = total_c

    if result == 100000 * n + 1:
        result = -1

    return  result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
import itertools
from operator import add

n, m, x = map(int, input().split())
C = [[]] * (n + 1)
ans = -1

for i in range(1, n + 1):
    C[i] = list(map(int, input().split()))
for i in range(1, n + 1):
    pares = list(itertools.combinations(range(1, n + 1), i))
    for pare in pares:
        A = [0] * (m + 1)
        for el in pare:
            A = list(map(add, A, C[el]))
        flag = True
        for a in A[1:]:
            if not a >= x:
                flag = False
                break
        if flag:
            if A[0] < ans or ans == -1:
                ans = A[0]
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

ok = False
cur_price = (10 ** 5) * n + 1
for i in range(1, n + 1):
    answers = list(itertools.combinations(range(n), i))
    # print(answers)
    for ans_list in answers:
        sum_list = [0] * (m + 1)
        # print(sum_list)
        for ans in ans_list:
            # print(all_list[int(ans[0])])
            sum_list = [a + b for a, b in zip(sum_list, all_list[int(ans)])]
        # print(sum_list)
        if min(sum_list[1:]) >= x:
            if sum_list[0] < cur_price:
                cur_price = sum_list[0]
                ok = True

if ok:
    print(cur_price)
else:
    print(-1)

Submission status: Accepted

Solution code:
import itertools

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


All = [0] * (M+1)
for book in books:
  All = [x + y for (x, y) in zip(All, book)]
Min = All[0]
if all([i >= X for i in All[1:]]):
  for bks in itertools.product([0,1], repeat=N):
    ans = [0] * (M+1)
    par = [i for i, x in enumerate(bks) if x == 1]
    for book in par:
      ans = [x + y for (x, y) in zip(ans, books[book])]
    if all([i >= X for i in ans[1:]]) and Min > ans[0]:
      Min = ans[0]
  print(Min)
else: print(-1)

Submission status: Accepted

Solution code:
import numpy as np

n,m,x=map(int,input().split())
ca=[]
for _ in range(n):
  ca.append(list(map(int,input().split())))
# print(ca)
minimum=10**7

for i in range(2**n):
#  print(i)
  tmp=[]
  tmp2=[0]*(m+1)
  cnt=0
  for j in range(n):
    if ((i >> j) & 1):
      tmp.append(ca[j])
      cnt+=1
#  print(tmp)
  for k in range(cnt):
    for l in range(m+1):
      tmp2[l]+=tmp[k][l]
# print(tmp2)
  if min(tmp2[1:])>=x:
    minimum=min(minimum,tmp2[0])
print(minimum if minimum < 10**7 else '-1')

Submission status: Accepted

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

Alist = []
Clist = []

for i in range(N):
    tmpAlist = list(map(int, input().split()))
    Clist.append(tmpAlist.pop(0))
    Alist.append(tmpAlist)

min_money = 10 ** 5 * 12 + 1

# どの本を選ぶかのパターンのループ
for bits in range(1, 2 ** N):
    #print("bits:" + bin(bits))
    rikaido_list = [0] * M
    tmp_money = 0

    # 選ばれた本に対する処理のループ
    for bit_shift in range(N):
        if (bits >> bit_shift) & 1 != 1:
            continue
        #print("bit_shift:" ,bit_shift)
        tmp_money += Clist[bit_shift]
        for i in range(M):
            rikaido_list[i] += Alist[bit_shift][i]
    
    # 理解度が全てXを超えているかの確認
    ok_flag = True
    for i in range(M):
        if rikaido_list[i] < X:
            ok_flag = False
            break  
    if ok_flag and tmp_money < min_money:
        min_money = tmp_money

if min_money < 10 ** 5 * 12 + 1:
    print(min_money)
else:
    print(-1)

Submission status: Accepted

Solution code:
import numpy as np

N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for n in range(N)]
npbooks = np.array(books)

def can_achieve(points, target):
    return all(points >= target)

def make_subsets(whole_list):
    subsets = []
    for i in range(1 << len(whole_list)):
        output = []
        for j in range(len(whole_list)):
            if ((i >> j) & 1) == 1:
                output.append(whole_list[j])
        subsets.append(output)
    return subsets[1:]

subsets = make_subsets([i for i in range(N)])
values = []
for subset in subsets:
    total = np.array([0 for _ in range(M+1)])
    for idx in subset:
        total += books[idx]
    if can_achieve(total[1:], X):
        values.append(total[0])
if values == []:
    print(-1)
else:
    print(min(values))

Submission status: Accepted

Solution code:
import sys
N, M, X = map(int, sys.stdin.readline().split())
CA = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
C = [CA[i][0] for i in range(N)]
A = [CA[i][1:] for i in range(N)]
ans = 10 ** 20
for i in range(2 ** N):
    TMP = [0] * M
    op = [0] * N
    c = 0
    for j in range(N):
        if (i >> j) & 1:
            op[j] = 1
    for k in range(len(op)):
        if op[k]:
            TMP = list(map(lambda x,y: x + y, TMP, A[k]))
            c += C[k]
    TMP_2 = [l for l in TMP if l >= X]
    if len(TMP_2)== M:
        ans = min(ans, c)
if ans == 10 ** 20:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=[list(map(int, input().split())) for i in range(n)]
bb=[0]*m
c=[]
cc=0
for i in range(n):
    cc+=a[i][0]
for i in range(m):
    for j in range(n):
        bb[i]+=a[j][i+1]
if any(bb[k]< x for k in range(m)):
  print(-1)
"""
d=[[] for i in range(m)]
money=0
i=0
def func(i,):
    if i==m:
        sum
        return money
    if func(i+1,money):
        return true
"""
def dec2bin(target):
    amari=[]
    while target !=0:
        amari.append(target % 2)
        target = target //2
    if len(amari)!=n:
        while len(amari)!=n:
            amari.append(0)
    amari.reverse()
    return amari
p=[]
for j in range(2**n):
    p.append(dec2bin(j))
for i in range(2**n):
    money=0
    b=[0]*m
    for j in range(n):
        if p[i][j]==1:
            money+=a[j][0]
            for aaa in range(m):
                b[aaa]+=a[j][aaa+1]
    if all(b[l]>=x for l in range(m)):
        c.append(money)

        
if len(c)>0:
  print(min(c))

Submission status: Accepted

Solution code:
#from collections import defaultdict, deque
import itertools
import numpy as np

def main():
    N, M, X = tuple(int(c) for c in input().split(' '))
    C = []
    A = []
    for _ in range(N):
        tmp = tuple(int(c) for c in input().split(' '))
        C.append(tmp[0])
        A.append(np.array(tmp[1:]))

    # max_rikai = np.zeros(M)
    # for i in range(N):
    #     max_rikai += A[i]
    # #print(max_rikai)
    # if min(max_rikai) < X:
    #     print(-1)
    #     exit()

    #c_index = [(i, C[i]) for i in enumerate(C)]
    cmin = -1
    for n in range(1, N+1):
        for t in itertools.combinations(range(N), n):
            ri = np.zeros(M)
            ctmp = 0
            for i in t:
                ri += A[i]
                ctmp += C[i]
            if min(ri) >= X:  #すべて理解できた
                if cmin == -1:
                    cmin = ctmp
                elif ctmp < cmin:
                    cmin = ctmp
    print(cmin)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# m 個のアルゴリズムを学びたい
# n 冊の参考書
# x 必要な理解度
n,m,x = map(int,input().split())
book = [list(map(int,input().split())) for _ in range(n)]
#n,m,x = 2,1,10
#book = [[1, 2, 2, 2], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10], [100, 10, 10, 10]]
#book = [[110,5],[100,5]]

def listadd(a,b,n):
  c = [0] * n
  for i in range(n):
    c[i] = a[i]+b[i]
  return c

ans = 0
for candi in range(0,2**n): # 読む本の候補リスト
  s = [0] * (m + 1)

  for i in range(n):
    #print(candi >> i & 1) 
    if candi >> i & 1:
      s = listadd(s,book[i],m+1)
  
  ck = 1
  for j in range(1,m+1):
    if s[j] < x:
      ck = 0
      break
    else:
      ck *= 1

  if ck:
    if ans:
      ans = min(ans,s[0])
    else:
      ans = s[0]

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

Submission status: Accepted

Solution code:
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
    n, m, x = map(int, input().split())
    c, a = [0]*n, [[] for i in range(n)]
    for i in range(n):
        hoge = list(map(int, input().split()))
        c[i], a[i] = hoge[0], hoge[1:m+1]
    hoge = list(range(n))
    cost = []
    kumi = []
    for i in range(2,n+1):
        kumi += list(itertools.combinations(hoge,i))
    for i in range(n):
        bit = 0
        for j in range(m):
            if a[i][j] < x:
                bit = 1
                break
        if bit == 0:
            cost.append(c[i])
    for i in range(len(kumi)):
        for j in range(m):
            huga = 0
            hoge = 0
            bit = 0
            for k in kumi[i]:
                huga += a[k][j]
                hoge += c[k]
            if huga < x:
                bit = 1
                break
        if bit == 0:
            cost.append(hoge)
    if len(cost) == 0:
        print(-1)
    else:
        print(min(cost))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import numpy as np
from itertools import chain,combinations
def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    for _ in range(N):
        CA = list(map(int, input().split()))
        C.append(CA[0])
        A.append(CA[1:])
    score = [0] * M
    A = np.array(A)
    if np.sum(np.sum(A, axis=0) < X) > 0:
        print('-1')
    else:
        PS = list(powerset([i for i in range(N)]))
        min_money = 10**9
        for Set_list in PS:
            X_sum = np.zeros(M, dtype=int)
            money = 0
            for i in Set_list:
                X_sum += A[i]
                money += C[i]
            if np.sum(X_sum < X) == 0 and money < min_money:
                min_money = money
        print(min_money)
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools 
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in [0]*n]
cl, al = [], []
for c, *a in ca:
    cl += [c]
    al += [a]
za = [list(i) for i in zip(*al)]
if any(sum(i)<x for i in za):
    print(-1)
else:
    ans = sum(cl)
    for num in range(n-1, 0, -1):
        for i in itertools.combinations(ca, num):
            tmp = [0]*m
            c = 0
            for j in i:
                c += j[0]
                for k in range(m): tmp[k] += j[k+1]
            if all(i>=x for i in tmp):
                ans = min(ans, c)
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as comb
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]
Cans = -1
for i in range(1, N+1):
    for lsts in comb(CA, i):
        Csum = 0
        buf = [0]*M
        for lst in lsts:
            Csum += lst[0]
            for j, v in enumerate(lst[1:]):
                buf[j] += v

        if Cans == -1 or Csum < Cans:
            flag = True
            for v in buf:
                if v < X:
                    flag = False
                    break
            if flag:
                Cans = Csum

print(Cans)

Submission status: Accepted

Solution code:

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

    ans = 1<<60
    for bit in range(1<<N):
        G = [0]*M
        cost = 0
        ok = False
        for i in range(N):
            if bit>>i & 1:
                c, *book = AB[i]
                cost += c
                for num, b in enumerate(book):
                    G[num] += b
        for g in G:
            if g < X:
                break
        else:
            ok = True
        if ok:
            ans = min(ans, cost)
    print(ans if ans < 1<<60 else -1)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import product

N,M,X=(int(x) for x in input().rstrip('\n').split())
pat = [x for x in product([0,1], repeat=N)]
OK = []
C={}
for i in range(N):
  C[i]=[int(x) for x in input().rstrip('\n').split()]
for i in pat:
  ans = [0]*(M+1)
  for x in range(N):
    add =  [y*i[x] for y in C[x]]
    ans = [y + z for (y,z) in zip(add,ans)]
  if all(y>=X for y in ans[1:]):
    OK.append(ans[0])
if len(OK) >0:
  print(min(OK))
else:
  print('-1')

Submission status: Accepted

Solution code:
import numpy as np
import math


n,m,x = map(int, input().split())
lis = [np.asarray(list(map(int, input().split()))) for _ in range(n)]
lis = np.array(lis)

res = []
for i in range(2**n):
    t = np.array([0]*(m+1))
    for j in range(n):
        if ((i >> j) & 1):
            t += lis[j]
    res.append(t)

res = np.array(res)

z = math.inf

for i in res:
    if np.amin(i[1:]) >= x and i[0] < z:
        z = i[0]

print(z if z != math.inf else -1)