Problem:


Score : 300 points

Problem

Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0.

Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M).
There is no other way to increase the understanding levels of the algorithms.

Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Constraints

All values in input are integers.

1\leq N, M\leq 12

1\leq X\leq 10^5

1\leq C_i \leq 10^5

0\leq A_{i, j} \leq 10^5

Input

Input is given from Standard Input in the following format:

N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M}

Output

If the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.

Sample Input 1

3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

Sample Output 1

120

Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.

Sample Input 2

3 3 10
100 3 1 4
100 1 5 9
100 2 6 5

Sample Output 2

-1

Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.

Sample Input 3

8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2

Sample Output 3

1067



Sample input:
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9


Sample output:
120

Submission status: Wrong Answer

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

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

# どの本を選ぶかのパターンのループ
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:
    print(min_money)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import copy
n, m, x = map(int, input().split())
my_level = [0]*m
book_list = []

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


def list_add(deep_list, length):
    temp = [0]*length
    for fun_i in deep_list:
        for fun_j in range(len(fun_i)):
            temp[fun_j] += fun_i[fun_j]
    return temp


temp_list = copy.copy(book_list)
for i in range(2, m+1):
    for j in itertools.combinations(book_list, i):
        temp_list.append(list_add(j, m+1))

book_list = copy.copy(temp_list)

def check_ok(book,x):
    for i in range(1,len(book)):
        if book[i] < x:
            return False
    return True


price_list = [book[0] for book in book_list if check_ok(book, x)]
if len(price_list) == 0:
    print('-1')
else:
    print(min(price_list))

Submission status: Wrong Answer

Solution code:
import itertools

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

All = [0] * (M+1)
for book in books:
  All = [x + y for (x, y) in zip(All, book)]
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]
    ans = [0] * (M+1)
  print(Min)
else: print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
 
N, M, X = list(map(int,input().split()))
A = []
for i in range(N):
  A.append(list(map(int,input().split())))
sum = []
subsets=[]
for i in range(len(A) + 1):
    for c in combinations(A, i):
        subsets.append(list(c))
 
print(subsets)
for i in subsets:
  tmp = [0]*6
  if len(i) == 1:
    sum.append(i[0])
  elif len(i) == 0:
    sum.append([0]*6)
  else:
    for j in i:
      tmp = list(map(lambda a,b: a + b, tmp,j))
    sum.append(tmp)
print(sum)
    
min_price = 1000000
 
for i in sum:
  t = 0
  for j in i:
    if X > j:
      t = 1
  if t == 0:
    min_price = min(min_price, i[0])
 
if min_price == 1000000:
  print(-1)
else:
  print(min_price)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import itertools
import numpy as np

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

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

# print(data)
ans = 2**63-1
for i in itertools.product([0, 1], repeat=n):
    # print(i)
    data_tmp = np.zeros(m+1, dtype=np.int)
    for index in range(len(i)):
        if i[index] == 0:
            continue
        data_tmp += data[index, :]

    if np.all((data_tmp >= x)):
        ans = min(ans, data_tmp[0])
        # print(data_tmp)

if ans == 2**63-1:
    print(-1)
else:
    print(int(ans))

Submission status: Wrong Answer

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:
            pass
        lst_res.append(res[0])

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

Submission status: Wrong Answer

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**6

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**6 else '-1')

Submission status: Wrong Answer

Solution code:
import itertools

N, M, X = map(int, input().split())
C = []; A = []; T = []
for _ in range(N):
    s = list(map(int, input().split()))
    T.append(s)


comb = []

for i in range(1,N):
    comb.append(list(itertools.permutations(T, i)))

comb = itertools.chain.from_iterable(comb)
count = []

for j in comb:
    t = [0, 0, 0, 0]
    for k in range(len(j)):
        t[0] += j[k][0]
        t[1] += j[k][1]
        t[2] += j[k][2]
        t[3] += j[k][3]
    count.append(t)

count.sort()


for i in count:
    if min(i[1:]) >= X:
        print(i[0])
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

C = np.array([list(map(int, input().split())) for _ in range(N)])
# print(C)
sum_C = np.sum(C,axis=0)
# print(sum_C)

for num in sum_C:
    if num < X:
        print(-1)
        exit()

cost = float("inf")

for ii in [0, 1]:
    for i in range(M+1):
        cc = sorted(C, key=lambda x:x[0], reverse=True)
        ccc = np.array(sorted(cc, key=lambda x:x[i], reverse=ii))
        # print("ccc", ccc)
        sum_Ccopy = sum_C.copy()
        for j in range(N):
            sum_Ccopy -= ccc[j]
            # print("sum_Ccopy", sum_Ccopy)
            # print(np.all(sum_Ccopy[1:] >= X))
            # print(sum_Ccopy[0])
            if np.any(sum_Ccopy[1:] < X):
                break
                # print(sum_Ccopy[0])
            cost = min(cost, sum_Ccopy[0])
            # print(cost)
    
print(cost)

Submission status: Wrong Answer

Solution code:
from itertools import product

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

minimum_cost = float('inf')

buy_selections = product([1, 0], repeat=n)
for selection in buy_selections:
    bought_books = [books[i] for i in range(n) if selection[i]]
    
    total_each = [0] * m
    for book in bought_books:
        for i in range(m):
            total_each[i] += book[i]
    
    if any([total < x for total in total_each[1:]]):
        continue
    if total_each[0] < minimum_cost:
        minimum_cost = total_each[0]

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

Submission status: Wrong Answer

Solution code:
def mysum(A, B):
    C = [0] * len(A)
    for i in range(len(A)):
        C[i] = A[i] + B[i]
    return C


def mytruthy(A, X):
    for a in A:
        if a < X:
            return False
    return True


def c():
    N, M, X = map(int, input().split())
    R = {}
    costs = []

    for i in range(N):
        V = list(map(int, input().split()))
        if i == 0:
            R['0'*N] = [0] * (M + 1)
            R['1' + '0'*(N-1)] = V
        else:
            newR = {}
            for k in R.keys():
                k2 = k[:i] + '1' + k[i+1:]
                newR[k2] = mysum(R[k], V)
                if mytruthy(newR[k2][1:], X):
                    costs.append(newR[k2][0])
            R.update(newR)

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


##########
if __name__ == "__main__":
    c()

Submission status: Wrong Answer

Solution code:
n,m,x = map(int, input().split())
data_list = []
for i in range(n):
    data_list.append(list(map(int, input().split())))
    
base = 1000000
price = 1200000

data_ = [0]*(m+1)
for i in range(len(data_list)):
    for j in range(m+1):
        data_[j] += data_list[i][j]
        
min_data = min(data_[:-1])
                
if min_data < x:
    print("-1")
else:
    for i in range(2 ** n):
        value_list = [0]*(m+1)
        value = []
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                value.append(data_list[j])
                    
        for i in range(len(value)):
            for j in range(m+1):
                value_list[j] += value[i][j]
                
        if min(value_list[:-1]) >= x and value_list[0] < price:
            price = value_list[0]
    
    print(price)

Submission status: Wrong Answer

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

MOD = 10**9+7
a = [0]*M
value = 0
ans = MOD

for i in range(2**N):
    if min(a) >= X :
        ans = min(ans,value)
    a = [0]*M
    value = 0

    for j in range(M+1):
        if(i >> j) & 1:
            for k in range(M):
                a[k] += A[j][k+1]
            value += A[j][0]

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m=[i+1 for i in range(N)]

from itertools import combinations

minmoney=float('inf')
for k in range(M):
  for i in combinations(m,k+1):
      #print(i)
      money=0
      r=[0]*M
      for j in range(len(i)):
          money+=CA[i[j]-1][0]
          #print("-------")
          #print(r)
          #print(CA[i[j]-1][1:])
          
          r=np.array(r)+np.array(CA[i[j]-1][1:])
          #print(CA[i[j]-1][0])
      #print(r)   
      n = sum(x>=X for x in r)
      if n==M and money<minmoney:
          minmoney=money
if minmoney==float('inf'):
  print(-1)
else:
  print(minmoney)

Submission status: Wrong Answer

Solution code:
N, M, XX = (int(i) for i in input().split())  

C = []
X = []
for _ in range(N):
    tmp = [int(i) for i in input().split()] 
    c = tmp[0]
    x = tmp[1:]
    C.append(c)
    X.append(x)

totalC = 1000000
for ho in range((2 ** N)):
    tmp_c = 0
    tmp_x = [0] * (M)

    tmp = format(ho, '013b')[13-N:]
    for i in range(len(tmp)):
        if tmp[i] == "1":
            tmp_c += C[i]
            for ii in range(M):
                tmp_x[ii] += X[i][ii]


    flag = True
    for fu in tmp_x:
        if fu < XX:
            flag = False
    
    if flag & (tmp_c < totalC):
        totalC = tmp_c

if totalC == 1000000:
    print("-1")
else:
    print(totalC)

Submission status: Wrong Answer

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

temp_all = []
s = [X]*M
temp_all = [list(map(int, input().split())) for _ in range(N)]
ans = 0
book  = N
while sum(s) != 0:
    if book == 0:
        ans = -1
        break
    min_value = 10 ** 5 + 1
    min_index = 0
    for n in range(book):
        temp = temp_all[n]
        q = sum([min(t, x) for x, t in zip(s, temp[1:])])
        if q != 0:
            value = temp[0]/q
            if value < min_value:
                min_value = value
                min_index = n

    s = [max(0, x - t) for x, t in zip(s, temp_all[min_index][1:])]
    ans += temp_all[min_index][0]
    book -= 1
    del temp_all[min_index]

print(ans)

Submission status: Wrong Answer

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):
        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: Wrong Answer

Solution code:
import sys
n,m,x=map(int,input().split())
d=[0]*m
l=[]
cost=[]
for _ in range(n):
	l.append(list(map(int,input().split())))
	cost.append(l[-1][0])
temp=[]
#print(cost)

for i in range(m):
	t=[]
	for j in range(n):
		t.append(l[j][i])
	temp.append(t)
price=sys.maxsize
res=0
for i in range(n):
	for j in range(n):
		f=0
		for k in range(m):
			if sum(temp[k][i:j+1])<x:
				f=1
				break
		#print(sum(cost[i:j]))
		if f==0:
			res=1	
			#print(sum(cost[i:j+1]))
			if sum(cost[i:j+1])<price:
				price=sum(cost[i:j+1])
print(price if res ==1 else -1)

Submission status: Wrong Answer

Solution code:
import copy
def c167(n, m, x, cali):

    ans = 0
    skill = [0]*m
    califlag = [True]*n

    for i in cali:
        ans += i[0]
        for w in range(m):
            skill[w] += i[w+1]

    for i in skill:
        if i < x:
            return -1

    cali.sort(reverse=True, key=lambda x: (x[0]))
    mans = copy.copy(ans)

    for w in range(n):
        flag = True
        for i in range(m):
            if skill[i]-cali[w][i+1] < x:
                flag = False
        if flag and califlag:
            for i in range(m):
                skill[i] -= cali[w][i+1]
            califlag[w] = False
            mans -= cali[w][0]

    cali.sort(key=lambda x: (x[0]))
    for w in range(n):
        flag = True
        for i in range(m):
            if skill[i]-cali[w][i+1] < x:
                flag = False
        if flag and califlag:
            for i in range(m):
                skill[i] -= cali[w][i+1]
            califlag[w] = False
            ans -= cali[w][0]

    return min(mans,ans)

def main():
    n, m, x = map(int, input().split())
    cali = [list(map(int, input().split()))for i in range(n)]
    print(c167(n, m, x, cali))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# 縦の合計
sums = [sum(CA[i][j] for i in range(N)) for j in range(M + 1)]

# print(CA)
# print(sums)

if any(sums[j + 1] < X for j in range(M)):
    print(-1)
    exit()


# 価格の高い順に並び替え
for ca in sorted(CA, key=lambda x: x[0], reverse=True):
    # print(ca)
    # X に達しないならスキップ
    if any(sums[j + 1] - ca[j + 1] < X for j in range(M)):
        continue

    sums[0] -= ca[0]
    for j in range(M):
        sums[j + 1] -= ca[j + 1]

print(sums[0])

Submission status: Wrong Answer

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

import itertools

# スペース区切りの整数の入力
N, M, X = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
input_list = [list(map(int, input().split())) for i in range(N)]

#print(input_list)
ans = -1
flg=1
for i in range(N):
    if i ==0:
        continue
    c = list(itertools.combinations(input_list, i))
    #print(c)
    flg=1
    for l in c:
        #print(l)
        flg=1
        for j in range(M):
            sum=0
            for k in range(i):
                #print(l[k][j+1])
                sum=sum+l[k][j+1]
            #print(sum)
            if sum<X:
                flg=0
        if flg==1:
            sum=0
            for j in range(i):
                sum=sum+l[j][0]
            if ans==-1:
                ans = sum
            elif sum<ans:
                ans = sum
        #print(ans)


print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def yn(t,x):
  for j in range(len(t)-1):
    if t[j+1] < x:
      return False
  return True
  

n,m,x=list(map(int,input().split()))
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
  
a=np.array(a)
a=a[np.argsort(a[:,0])]
flag=0
t=np.sum(a,axis=0)
for i in range(m):
  if t[i+1] < x:
    flag=1
    break
    
for i in range(1,n+1):
  if yn(t-a[-i],x):
    t = t-a[-i]

if flag==1:
  print("-1")
else:
  print(t[0])

Submission status: Wrong Answer

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):
            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: Wrong Answer

Solution code:
#C
import itertools
n, m, x = map(int, input().split())
ca = [list(map(int, input().split()))for i in range(n)]
l = []
ans=1e6
for i in range(1,n+1):
    for j in itertools.combinations(range(1, n + 1), i):
        # print(j)
        tmp=0
        count = 0
        li = [0] * m
        for k in j:
            # print(k)
            tmp+=ca[k-1][0]
            for o in range(m):
                # print(o)
                li[o] += ca[k - 1][o+1]
                if o == m - 1:
                    # print(li)
                    for p in li:
                        if p >= x:
                            count += 1
                        else:
                            break
        if count >= m:
            # print(count,m,j)
            ans = min(ans, tmp)
if ans != 1e6:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools

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

Money=0

lst=range(N)
combs = []

for i in range(1, len(lst)+1):
    els = [list(x) for x in itertools.combinations(lst, i)]
    combs.extend(els)

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


Tmp=[0]*(len(combs))

for i in range(len(combs)):
    Skill=[0]*M
    for j in range(len(combs[i])):
        for k in range(M):
            Skill[k]+=inList[combs[i][j]][k]
        Tmp[i]+=inList[combs[i][j]][0]

    ok=True
    for k in range(M):
        if(Skill[k]<X):
            ok=False
    if(ok==False):
        Tmp[i]=10000000000

if(min(Tmp)==10000000000):
    print(-1)
else:
    print(min(Tmp))

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
import sys

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

C = []
A = []
ALL = []

for n in range(N):
  Y = list(map(int, input().split()))
  ALL.append(Y)
  C.append(Y[0])
  A.append(Y[1:])

ALL = np.sort(ALL, axis=0)

ok_index = []
for n in range(N):
  for i in itertools.permutations(ALL, r=n+1):
      if n > 0:
        this_ar = np.sum(np.array(i), axis=0)
      else:
        this_ar = np.array(i)[0]
      if np.all(this_ar[1:]>=X):
        ok_index.append(this_ar[0])
        print(np.min(ok_index))
        sys.exit()
  if len(ok_index) > 0:
    print(np.min(ok_index))
    sys.exit()
if len(ok_index)==0:
  print(-1)
else:
  print(np.min(ok_index))

Submission status: Wrong Answer

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

nls = np.array(c)
f=0
if not all(np.sum(nls, axis=0) > x):
    f = 1
    print("-1")   
else:
    import itertools
    import pprint
    result=[]
    final =[]
    for n in range(1,len(c)+1):
        for conb in itertools.combinations(c, n):
            result.append(list(conb))
    for l in result:
        l=np.array(l)
        tmp = np.sum(l, axis=0)
        # print("tmp", tmp)
        if all(tmp >= x):
            final.append(tmp.tolist())
    final.sort()
    print(final[0][0])

Submission status: Wrong Answer

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

onedan = []

for j in range(1,N+1):
    CCj = list(itertools.combinations(C,j))
    for k in range(len(CCj)):
        kahi = True
        for l in range(1,M):
            ri = sum([CCj[k][m][l] for m in range(j)])
            if ri < X:
                kahi = False
                break
        if kahi:
            onedan.append(sum([CCj[k][m][0] for m in range(j)]))
if onedan == []:
    print(-1)
else:
    print(min(onedan))

Submission status: Wrong Answer

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

MOD = 10**9+7
a = [0]*M
value = MOD
ans = MOD

for i in range(2**N):
    if min(a) >= X :
        ans = min(ans,value)
    a = [0]*M
    value = 0

    for j in range(M+1):
        if(i >> j) & 1:
            for k in range(M):
                a[k] += A[j][k+1]
            value += A[j][0]

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

m=[i+1 for i in range(N)]

from itertools import combinations

minmoney=10**10
for k in range(M):
  for i in combinations(m,k+1):
      #print(i)
      money=0
      r=[0]*M
      for j in range(len(i)):
          money+=CA[i[j]-1][0]
          #print("-------")
          #print(r)
          #print(CA[i[j]-1][1:])
          
          r=np.array(r)+np.array(CA[i[j]-1][1:])
          #print(CA[i[j]-1][0])
      #print(r)   
      n = sum(x>=X for x in r)
      if n==M and money<minmoney:
          minmoney=money
if minmoney==10**10:
  print(-1)
else:
  print(minmoney)

Submission status: Wrong Answer

Solution code:
N, M, XX = (int(i) for i in input().split())  

C = []
X = []
for _ in range(N):
    tmp = [int(i) for i in input().split()] 
    c = tmp[0]
    x = tmp[1:]
    C.append(c)
    X.append(x)

totalC = 1000000
for ho in range((2 ** N)):
    tmp_c = 0
    tmp_x = [0] * (M)

    tmp = format(ho, '012b')[12-N:]
    for i in range(len(tmp)):
        if tmp[i] == "1":
            tmp_c += C[i]
            for ii in range(M):
                tmp_x[ii] += X[i][ii]


    flag = True
    for fu in tmp_x:
        if fu < XX:
            flag = False
    
    if flag & (tmp_c < totalC):
        totalC = tmp_c

if totalC == 1000000:
    print("-1")
else:
    print(totalC)

Submission status: Wrong Answer

Solution code:

from math import inf
from itertools import combinations
n,m,x=map(int,input().split())
book=[]
for i in range(n):
    book.append(list(map(int,input().split())))
temp=range(n)
com=[]
for i in range(1,m+1):
    com+=list(combinations(temp,i))
ans=inf
# print(com)
for i in range(len(com)):
    temp=1
    for k in range(1,m+1):
        s=0
        for j in com[i]:
            s+=book[j][k]
        if(s<x):
            temp=0
            break
    if(temp):
        p=0
        for j in com[i]:
            p+=book[j][0]
        ans=min(ans,p) 
if(ans==inf):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
s = []
mini = 10**9
for i in range(n):
    s.append(list(map(int,input().split())))
for i in range(2**n):
    l = [0]*m
    flag = 0
    for j in range(n):
        if ((i>>j) & 1):
            for k in range(m):
                l[k] += s[j][k]
    for check in range(1,len(l)):
        if l[check] < x:
            flag = 1  
    if flag == 0:
        mini = min(mini, l[0])
if (mini==10**9):print(-1)
else: print(mini)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M,X=map(int,input().split())
A=[[]for i in range(N+1)]
ans=10**5
for i in range(N):
    A[i]=(list(map(int,input().split())))
A=np.array(A)
#print(A)
for i in range(2**N):
    B=np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            B+=A[j]
    #print(B)
    if not B.all(0):
         continue
    elif ans>=B[0] and X<=min(B[1:M+1]):
        ans=B[0]
if ans==100000:
    print(-1)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np

if __name__ == '__main__':
    n,m,x = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    c, a = [], np.ndarray((n,m))

    for i in range(n):
        ls  = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        tc, ta = ls[0], ls[1:]
        c.append(tc)
        a[i] = ta

    mini = 1000000
    for q in range(n):
        indices = itertools.permutations(range(n), q)
        for ix in indices:
            if ix == ():
                continue
            if all([True if r >= 10 else False for r in sum([a[i] for i in ix])]):
                tmini = sum([c[i] for i in ix])
                if mini > tmini:
                    mini = tmini
    if mini == 1000000:
        print('-1')
    else:
        print(mini)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from collections import deque

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

Asum = [0]*M
for i in range(N):
  for j in range(M):
    Asum[j] += CA[i][j+1]

for i in range(M):
  if Asum[i] < X:
    print(-1)
    exit()

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

Submission status: Wrong Answer

Solution code:
import itertools

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

C = [0] * N
A = [list() for _ in range(N)]

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

ans = sum(C)

b = False
for i in range(1, N+1):
    for j in itertools.combinations(range(N), i):
        # print(j)
        a = [0] * M
        for k in j:
            for l in range(M):
                a[l] += A[k][l]
        # print("a ", a)
        for aa in a:
            if aa < X:
                break
        else:
            ans = min(ans, sum(C[k] for k in j))
            # print(ans, "!!!")
            b = True
    if b:
        break

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

Submission status: Wrong Answer

Solution code:
import itertools


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

books = {}
for i in range(N):
    a = [int(j) for j in input().split()]
    books[a.pop(0)] = a

result = []
for n in range(1, N + 1):
    for conb in itertools.combinations(books.keys(), n):
        result.append(conb)

price = {}
for i in result:
    price[i] = sum(i)
price_sorted = sorted(price.items(), key=lambda x:x[1])

ans = -1
for k, v in price_sorted:
    point = [0] * M
    for i in k:
        for j in range(M):
            point[j] = point[j] + books[i][j]
    if all([X <= i for i in point]):
        ans = v
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, X = input().split()
i = 0
while i < int(N):
    A = input().split()
    C = A[0]
    Am = A[1:]
    i = i+1

Submission status: Wrong Answer

Solution code:
import sys,copy

N,M,X = list(map(int,input().split()))
C = [list(map(int,input().split())) for i in range(N)]
C.sort(key=lambda x: x[0],reverse = True)
total = [0]*(M+1)
for c in C:
    total = [x + y for (x,y) in zip(total,c)]

def j(l):
    flg=0
    for r in l[1:]:
        if r < X:
            flg=1
    if flg==1:
        return False
    else:
        return True


if j(total)== False:
    print(-1)
    sys.exit()

for i,c in enumerate(C):
    min = [x - y for (x,y) in zip(total,c)]
    if j(min):
        total = copy.copy(min)

if j(min):
    print(min[0])
else:
    print(total[0])

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x=map(int, input().split())
ca = [list(map(int, input().split())) for i in range(n)]
ca.sort(key=lambda x:x[0])

for i in range(n):
    for j in itertools.combinations(ca, i+1):
        p=[0]*(m+1)
        for k in range(m+1):
            for value in range(len(j)):
                p[k] += j[value][k]
        l_ans = [i for i in p[1:] if i >= x]
        if len(l_ans) >= m:
            print(p[0])
            exit()
        else:
            continue
print("-1")

Submission status: Wrong Answer

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

import itertools

# スペース区切りの整数の入力
N, M, X = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
input_list = [list(map(int, input().split())) for i in range(N)]

#print(input_list)
ans = -1
flg=1
for i in range(N):
    if i ==0:
        continue
    c = list(itertools.combinations(input_list, i))
    #print(c)
    flg=1
    for l in c:
        #print(l)
        flg=1
        for j in range(M):
            sum=0
            for k in range(i):
                #print(l[k][j+1])
                sum=sum+l[k][j+1]
            #print(sum)
            if sum<X:
                flg=0
        if flg==1:
            sum=0
            for j in range(i):
                sum=sum+l[j][0]
            if ans==-1 or sum < ans:
                ans = sum
        #print(ans)


print(ans)