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:
import sys
import os
import itertools

def file_input():
    f = open('ABC167/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    N,M,X=map(int, input().split())
    C=[0]*N
    A=[[0 for j in range(M)] for i in range(N)]
    for i in range(N):
        tmp=list(map(int, input().split()))
        C[i]=tmp[0]
        A[i]=tmp[1:]

    sum=0
    min=100000
    A_sum=[0]*M
    for i in range(N):
        for li in itertools.combinations(range(0,N),i+1):
            # print(li)
            sum=0
            A_sum=[0]*M
            for j in li:
                sum+=C[j]
                for l in range(M):
                    A_sum[l]+=A[j][l]
            # print(sum)
            for l in range(M):
                if A_sum[l]<X:
                    break
                if min>sum:
                    min=sum

    if min==100000:
        print(-1)
    else :
        print(min)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#import numpy as np
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

N,M,X=MI()
CA=LLI(N)

mi=10000000000000
ans=0

for i in range(1,N+1):
    kumi = itertools.combinations(CA,i)
    for k in kumi:
        target=[0]*(M+1)
        su=0
       
        for x in k:
            target = [a + b for (a,b) in zip(x,target)]
            su+=x[0]
           
        for j in range(1,len(target)):
            if X > target[j]:
                break
            else:
                mi=min(mi,su)
                ans+=1
if ans ==0:
    print(-1)
else:
    print(mi)

Submission status: Wrong Answer

Solution code:
import random
import math
import sys
import itertools
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
n,m,x = MI()
a = []
l = []
for i in range(n):
	a.append(LI())
for L in range(0, n+1):
    for subset in itertools.combinations(a, L):
        l.append(subset)
ans = 10**9
for i in l:
	q = [0]*m
	for j in range(len(i)):
		for z in range(m):
			q[z]+=i[j][z]
	boo = True
	for j in q[1:]:
		if j<x:
			boo = False
			break
	if boo and q[0]<ans:
		ans = q[0]
print(ans if ans!=10**9 else -1)

Submission status: Wrong Answer

Solution code:
import sys
N,M,X=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
#print(L)
price=[]
list_X=[X for i in range(M)]
for i in range(2**N):
  A=[0 for i in range(M+1)]
  for j in range(N):
    if (i>>j) & 1:
      A = [x+y for (x,y) in zip(A,L[j])] 
  #print(A)
  if A[1:] >= list_X:
    price.append(A[0])
#print(price)
if price ==[]:
  print(-1)
else:
  print(min(price))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N, M, X = map(int, input().split())
CAs = [[int(n) for n in input().split()] for _ in range(N)]

CAs.sort()

for i in range(1, N + 1):
    for cas in combinations(CAs, i):
        rikai = [0] * M
        kakaku = 0
        for ca in cas:
            for j in range(M):
                rikai[j] += ca[j + 1]
            kakaku += ca[0]
        if len(list(filter(lambda x: x < X, rikai))) == 0:
            print(kakaku)
            break
    else:
        continue
    break
else:
    print('-1')

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
# print(a)
ans=10**18
for i in range(1<<n):
  t_money=0
  t_rikai=[0]*m
  ok=True
  for j in range(n):
    if i&(1<<j): 
      t_money+=a[j][0]
      for k in range(m):
        t_rikai[k]+=a[j][k]
  for y,r in enumerate(t_rikai):
    if r>=x:
      pass
    else:
      ok=False
      break
  if ok:
    ans=min(t_money,ans)
  
if ans==10**18:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

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

c=10**5+1
p=0
for i in range(1,2**n+1):
    al=[0]*m
    cost=0
    for j in range(n):
        if (i>>j)&1:
            for k in range(m):
                al[k]+=lis[j][k]
            cost+=lis[j][0]
    if min(al)>=x:
        c=min(c,cost)
        p=1
print(c) if p==1 else print(-1)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
CA = [list(map(int, input().split())) for i in range(n)]
C = [CA[i][0] for i in range(n)]
A = [CA[i][1:] for i in range(n)]
for s in range(1 << n):
    X = [0 for j in range(m)]
    c = 0
    for i in range(n):
        if (s >> i) & 1 == 1:
            for j in range(m):
                X[j] += A[i][j]
            c += C[i]
    if all([X[j] >= x for j in range(m)]):
        print(c)
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def m():
    N, M, X = map(int, input().split())
    CA = [list(map(int, input().split())) for _ in range(N)]
    ans = float('inf')
    for i in range(2 ** N):
        b = bin(i)[2:]
        b = b.zfill(N)
        tmp = [0] * (M + 1)
        for j, v in enumerate(b):
            if v == '0':
                continue
            else:
                tmp[0] += CA[j][0]
                for k in range(M):
                    tmp[k+1] += CA[j][k]
        f = 1
        for p in range(M):
            if tmp[p+1] < X:
                f = 0
                break
        if f:
            ans = min(ans, tmp[0])
    if ans == float('inf'):
        return '-1'
    else:
        return ans


print(m())

Submission status: Wrong Answer

Solution code:
n, m, x = map(int,input().split())
hako = []#参考書、0=買わない、1=買う


def taka(y,z):
    global hako
    if len(z) == n:
        hako.append(z)
        return
    zz = z.copy()
    zz.append(y)
    for i in range(2):
        taka(i,zz)


for i in range(2):
    taka(i,[])

#print(hako)

sankousyo = []

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

takahasikunn = [0]*(m+1)

ans = 13*10**5

for i in hako:
    for j in range(n):
        if i[j] == 1:
            for k in range(m+1):
                takahasikunn[k] += sankousyo[j][k]
    for l in range(1,m+1):
        if takahasikunn[l] < x:
            break
        else:
            ans = min(ans,takahasikunn[0])
    #print(takahasikunn)
    takahasikunn = [0]*(m+1)

if ans == 13*10**5:
    ans = -1

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np
N, M, X = map(int, input().split())
xx = np.array([X for _ in range(M)])

C = {}
costs = []
for _ in range(N):
    c, *A = map(int, input().split())
    C[c] = A
    costs.append(c)
ans = float('inf')
for i in range(1, N+1):
    for comb in combinations(costs, i):
        tmp = 0
        x = xx.copy()
        for cost in comb:
            tmp += cost
            x -= np.array(C[cost])
        if len(x[x <= 0]) >= M:
            ans = min(ans, tmp)

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

Submission status: Wrong Answer

Solution code:
def solve():
    N, M, X = map(int, input().split())
    AC = []
    ans = 10**6
    for n in range(N):
        AC.append(list(map(int, input().split())))
    for i in range(2**N):
        level = [0]*M
        cost = 0
        for j in range(N):
            if ((i >> j) & 1):
                for l in range(M):
                    level[l] += AC[j][l+1]
                cost += AC[j][0]
        if (min(level) >= X) and (ans > cost):
            ans = cost
    if ans == 10**6:
        print(-1)
    else:
        print(ans)


solve()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(10**6)

INF = 10**10


def main(input, print):
    n, m, x = map(int, input().split())
    table = [[] for _ in range(n)]
    for i in range(n):
        table[i] = list(map(int, input().split()))
    ans = INF
    for i in range(1, n):
        p = itertools.combinations(range(n), i)
        for pj in p:
            t = 0
            mt = [0] * m
            for k in range(len(pj)):
                t += table[pj[k]][0]
                for l in range(m):
                    mt[l] += table[pj[k]][l+1]
            is_ok = True
            for l in range(m):
                if mt[l] < x:
                    is_ok = False
            if is_ok:
                ans = min(ans, t)
        if ans != INF:
            break
    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Submission status: Wrong Answer

Solution code:
import itertools

N, M, X = map(int, input().split())
ca = []
for _ in range(N):
  ca.append(list(map(int, input().split())))
  
ns = [i for i in range(N)]
price = 1000000000000
for r in range(1,N+1):
  for v in itertools.combinations(ns, r):
    flag = True
    for j in range(M):
      s = sum([ca[i][j+1] for i in v])
      print(v, s)
      if s < X:
        flag = False
        continue
    if flag:
      p = sum([ca[i][0] for i in v])
      price = min(price, p)
      
if price == 1000000000000:
  print(-1)
else:
  print(price)

Submission status: Wrong Answer

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

a=[]

for i in range(0,n):
    aa=input().split()
    for j in range(0,m+1):
        aa[j]=int(aa[j])
    a.append(aa)

smin=1000000000
d=1000000000


for i in range(0,2**n):
    mo=0
    x2=[1 for i2 in range(0,m)]
    
    for j in range(0,n):
        if ((i>>j)&1)==1:
            mo+=a[j][0]
            for k in range(0,m):
                x2[k]+=a[j][k+1]

    if min(x2)>=x:
        if mo<smin:
            smin=mo
    

if smin==d:
    print(-1)

else:
    print(smin)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#import numpy as np
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

N,M,X=MI()
CA=LLI(N)

mi=10000000
ans=0

for i in range(1,N+1):
    kumi = itertools.combinations(CA,i)
    for k in kumi:
        target=[0]*(M+1)
        su=0
       
        for x in k:
            target = [a + b for (a,b) in zip(x,target)]
            su+=x[0]
           
        for j in range(1,len(target)):
            if X > target[j]:
                break
            else:
                mi=min(mi,su)
                ans+=1
if ans ==0:
    print(-1)
else:
    print(mi)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N, M, X = map(int, input().split())
CAs = [[int(n) for n in input().split()] for _ in range(N)]

MAX = 10**5 * 12 + 1

print(CAs)
CAs.sort()
print(CAs)

for i in range(1, N + 1):
    # min_ = MAX
    for cas in combinations(CAs, i):
        rikai = [0] * M
        kakaku = 0
        for ca in cas:
            for j in range(M):
                rikai[j] += ca[j + 1]
            kakaku += ca[0]
        if len(list(filter(lambda x: x < X, rikai))) == 0:
            print(kakaku)
            break
    else:
        continue
    break
        #     min_ = min(min_, kakaku)
        # # print(cas, min_)
    # if min_ < MAX:
    #     print(min_)
    #     break
else:
    print('-1')

Submission status: Wrong Answer

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

def can_reach(M, CA, X):
    understandig_list = [0] * M
    for CAi in CA:
        for j in range(1, len(CAi)):
            understandig_list[j - 1] += CAi[j] 

    can = all([understandig >= X for understandig in understandig_list])

    return can


if not can_reach(M, CA, X):
    print('-1')
    exit(0)

print(0)

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
dic=[]
ans=10**6
ans_check=[0]*M
ans_t=0
for _ in range(N):
    dic.append(list(map(int,input().split())))
for i in range(0,2**N):
    tmp=i
    ans_t=0
    flag=0
    ans_check=[0]*M
    for j in range(N):
        index=tmp%2
        tmp=tmp//2
        if index==1:
            ans_t+=dic[j][0]
            for t in range(1,M+1):
                ans_check[t-1]+=dic[j][t]
    #print(ans_check)
    for d in ans_check:
        if d>=X:
            flag=1
        else:
            flag=0
            break
    if flag==1:
        ans=min(ans,ans_t)
    #print("ans",ans)
if ans==10**6:
    print(-1)
else:
    print(min(ans,ans_t))

Submission status: Wrong Answer

Solution code:
import itertools

n,m,x=map(int,input().split())
ca=[0]*n
num=[]
ls=[]
last=[]
test=0
ng=0
money=0
for i in range(n):
  ca[i]=input().split()
  num.append(i)
  
for j in range(1,n+1):
  ls=list(itertools.combinations(num,j))
  
  for k in range(len(ls)):
    test=0
    money=0
    ng=0
    for l in range(m):
      for p in range(j):
        test+=int(ca[ls[k][p]][l+1])
      if test<x:
        ng+=1
    if ng==0:
      for q in range(j):
        money+=int(ca[ls[k][q]][0])
      last.append(money)

if len(last)>0:
  print(str(min(last)))
else:
  print("-1")

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np
N,M,X = map(int, input().split())
#matrix = np.array([list(map(int, input().split())) for _ in range(N)])
matrix = np.random.rand(12,13)

min_price = 1e9
for n in range(N):
  for texts in combinations(matrix, n+1):
    summation = np.sum(texts, axis=0)
    price = summation[0]
    if all(summation[1:] >= X):
      if price < min_price:
        min_price = price

print(min_price if min_price < 1e9 else -1)

Submission status: Wrong Answer

Solution code:
def main():
  import itertools
  from sys import stdin
  N, M, X = map(int, input().split())
  s_list = [list(map(int, stdin.readline().split())) for _ in range(N)]
  nums = [0, 1]
  min_cos = 10 ** 10
  for balls in itertools.product(nums, repeat=N):
    cos = 0
    score = [0] * M
    v = list(balls)
    for i in range(N):
      if v[i] == 1:
        cos += s_list[i][0]
        score = [x + y for (x, y) in zip(score, s_list[i][1:])]
    if min(score) >= X and cos < min_cos:
      min_cos = cos
  print(min_cos)
  
main()

Submission status: Wrong Answer

Solution code:
import random
import math
import sys
import itertools
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
n,m,x = MI()
a = []
l = []
for i in range(n):
	a.append(LI())
for L in range(0, n+1):
    for subset in itertools.combinations(a, L):
        l.append(subset)
ans = 10**7
for i in l:
	q = [0]*m
	for j in range(len(i)):
		for z in range(m):
			q[z]+=i[j][z]
	boo = True
	for j in q[1:]:
		if j<x:
			boo = False
			break
	if boo and q[0]<ans:
		ans = q[0]
print(ans if ans!=10**7 else -1)

Submission status: Wrong Answer

Solution code:
import sys
N,M,X=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
#print(L)
price=[]
list_X=[X for i in range(M-1)]
for i in range(2**N):
  A=[0 for i in range(M)]
  for j in range(N):
    if (i>>j) & 1:
      A = [x+y for (x,y) in zip(A,L[j])] 
  #print(A)
  if A[1:] >= list_X:
    price.append(A[0])
#print(price)
if price ==[]:
  print(-1)
else:
  print(min(price))

Submission status: Wrong Answer

Solution code:
def solve():
    N, M, X = map(int, input().split())
    AC = []
    ans = 10**6
    for n in range(N):
        AC.append(list(map(int, input().split())))
    for i in range(2**N):
        level = [0]*M
        cost = 0
        for j in range(N):
            if ((i >> j) & 1):
                for l in range(M):
                    level[l] += AC[j][l+1]
                cost += AC[j][0]
        if (min(level) >= X) and (ans > cost):
            print(i, j)
            ans = cost
    if ans == 10**6:
        print(-1)
    else:
        print(ans)


solve()

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, X = map(lambda x: int(x), input().split(" "))

Ns = []
for _ in range(N):
    Ns.append(list(map(lambda x: int(x), input().split(" "))))

Ns = np.array(Ns)
Ms = np.sum(Ns, axis=0)

flag = True
for m in Ms:
    if m < X:
        flag = False
        break
if flag:

    Ns = Ns[np.argsort(Ns[:, 0])[::-1]]

    for n in Ns:
        flag = True
        temp_Ms = []
        for i in range(1, len(n)):
            m = Ms[i] - n[i]
            if m < X:
                flag = False
                break
            temp_Ms.append(m)
        if flag:
            Ms = [Ms[0]-n[0]]
            Ms.extend(temp_Ms)
    print(Ms[0])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

coin = []
for i in range(1, m+1):
  for v in itertools.combinations(books, i):
    comb = list(v)
    result = np.sum(comb, axis = 0)
    flag = True
    for j in range(1,m+1):
      if result[j] < x:
        flag = False
        break
    if flag:
      coin.append(result[0])

if len(coin) > 0:
  sorted(coin, reverse=False)
  print(coin[0])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:

def sumList(index,array):
    if index ==n:
        sumArray.append(array)
    else:
        sumList(index+1,array)
        nextArray =[0]*(m+1)
        for i in range(m+1):
            nextArray[i] +=array[i]+ list[index][i]
        sumList(index+1,nextArray)



if __name__ == '__main__':
    n,m,x = map(int, input().split())

    list = []
    for i in range(n):
        a = [int(i) for i in input().split()]
        list.append(a)
    firstArray = [0] * (m + 1)
    sumArray = []
    sumList(0,firstArray)

    min = 100000000
    print(sumArray)
    for i in sumArray:
        amount =0
        count =0
        for j in range(len(i)):
            if j == 0:
                amount =i[j]
            else:
                if i[j] >=x:
                    count+=1
        if count == m and min >= amount:
            min = amount

    if min == 100000000:
        print(-1)
    else:
        print(min)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,X = map(int,input().split())
CA = [np.array(list(map(int,input().split()))) for i in range(N)]
ans = -1
for i in range(2**N-1):
    tmp = 0
    und = np.zeros(M+1,dtype=int)
    flag = True
    for j in range(N):
        isget = i >> j & 1
        if isget == 1:
            und += CA[j]
            tmp += CA[j][0]
    for k in range(M):
        if und[k+1] < X:
            flag = False
            break
        if flag:
            if ans == -1:
                ans = tmp
            else:
                ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n, m, x = map(int, input().split())
caaa = [list(map(int, input().split())) for _ in range(n)]
ans = 10 ** 7
for i in range(1, n + 1):
    for caa in list(itertools.combinations(caaa, i)):
        c = 0
        aa = [0] * m
        for j in range(0, i):
            c += caa[j][0]
            for k in range(0, m):
                aa[k] += caa[j][k]
        if all(aa[l] >= x for l in range(m)):
            ans = min(c, ans)
print(-1 if ans == 10 ** 7 else ans)

Submission status: Wrong Answer

Solution code:
import sys
N,M,X=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
#print(L)
price=[]
list_X=[X for i in range(M-1)]
for i in range(2**N):
  A=[0 for i in range(M+1)]
  for j in range(N):
    if (i>>j) & 1:
      A = [x+y for (x,y) in zip(A,L[j])] 
  #print(A)
  if A[1:] >= list_X:
    price.append(A[0])
#print(price)
if price ==[]:
  print(-1)
else:
  print(min(price))

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x=map(int,input().split())
l=list()
for i in range(n):
    l.append(list(map(int,input().split())))
for i in range(1,n+1):
    for j in itertools.combinations(l,i):
        r=[0]*m
        a=0
        for k in j:
            p=0
            for i in range(1,m+1):
                r[i-1]+=k[i]
                a+=r[i-1]>=x
            if a==m:
                p=0
                for c in j:
                    p+=c[0]
                print(p)
                exit()
print(-1)

Submission status: Wrong Answer

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={}
check=0
for i in range(N):
  C[i]=[int(x) for x in input().rstrip('\n').split()]
for i in pat:
  ans = [0]*M
  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:]):
    check += 1
    OK.append(ans[0])
if check >0:
  print(min(OK))
else:
  print('-1')

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
l=[]
for i in range(n):
  s=list(map(int,input().split()))
  l.append(s)
ans=12*(10**5)
#print(l)
import itertools
now=0
oko=0
com=[i for i in range(n)]
while ans==12*(10**5) and now<=n:
  now+=1
  level=[0 for j in range(0,m+1)]
  for i in itertools.combinations(com, now):
    level=[0 for j in range(m+1)]
    money=0
    #print(i)
    for h in i:
      #print(h,"h")
      money+=l[h][0]
      for k in range(1,m+1):
        level[k]+=l[h][k]
    jud=0
    for ii in level:
      if ii>=x:
        jud+=1
    if jud==m:
      oko+=1
      #print("ok",i)
      ans=min(ans,money)
if oko==0:
  print("-1")
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
k=[0]*m
ans=0
e=0
f=0
for i in range(m):
  for c in range(n):
    k[i]+=l[c][i+1]
for i in range(n):
  ans+=l[i][0]
for i in range(m):
  if k[i]<x:
    break
  else:
    f+=1
d=[]
for q in range(n,0,-1):
  d.append(l[q-1])
for i in range(n):
  e=0
  for p in range(m):
    if k[p]-d[i][p+1]<x:
      break
    else:
      e+=1
  if e==m:
    for u in range(m):
      k[u]-=d[i][u+1]
    ans-=d[i][0]
if f!=m:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

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

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

min_amount = float('+inf')
has_sol = False

def dfs(idx, amt, skills):
    global arr
    global min_amount
    global x
    global has_sol

    if idx == len(arr):
        ok = all(j >= x for j in skills)

        if ok:
            has_sol = True
            min_amount = min(min_amount, amt)
        return

    dfs(idx+1, amt, skills)
    dfs(idx+1, amt+arr[idx][0], [j+arr[idx][i] for i, j in enumerate(skills)])

dfs(0, 0, [0]*m)

if not has_sol:
    print('-1')
else:
    print(min_amount)

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n, m, x = MI()
    li = [LI() for _ in range(n)]

    min = float(inf)
    for i in range(2 ** n):
        flag = True
        total = [0] * 4
        for j in range(n):
            if (i >> j) & 1:
                total = [x + y for (x, y) in zip(total, li[j])]

        for t in total[1:]:
            if t < x:
                flag = False

        if flag:
            if total[0] < min:
                min = total[0]

    if isinstance(min, float):
        print(-1)
    else:
        print(min)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def look_for_book(bklist):
    newlist = []
    for i in bklist:
        newlist.append(sum(i)/priceList[bklist.index(i)])
    theBook = newlist.index(max(newlist))
    return theBook


[n,m,x] = list(map(int, input().split()))
priceList = []
bookAbilityList = []
abilityList = []
price = 0
for i in range(m):
    abilityList.append(0)
for i in range(n):
    inputList = list(map(int, input().split()))
    priceList.append(inputList[0])
    bookAbilityList.append(inputList[1:])
loop = True
while loop:
    if bookAbilityList:
        theBook = look_for_book(bookAbilityList)
        for i in range(m):
            abilityList[i] += bookAbilityList[theBook][i]
        price += priceList[theBook]
        del bookAbilityList[theBook]
        del priceList[theBook]
        loop = False
        for i in abilityList:
            if i<x:
                loop = True
    else:
        price = -1
        break
print(price)

Submission status: Wrong Answer

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

ans=float("inf")
for i in range(N**2):
    a=[0]*M
    checked=[0]*M
    money=0
    cnt=0
    for j in range(N):
        if i%2==1:
            for k in range(M):
                a[k]+=A[j][k]
                if a[k]>=X and checked[k]==0:
                    cnt+=1
                    checked[k]+=1
            money+=cost[j]
        i//=2
    if cnt==M:
        ans=min(ans,money)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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:m+1])
S = sum(c)
ans = S +1
for i in range(2**n):
    cost = 0
    sum = [0,0,0]
    for j in range(n):
        if ((i>>j)&1):
            cost += c[j]
            sum = [x + y for (x,y) in zip(sum,a[j])]  
            if all(i>=x for i in sum) == True:
                obj = sum
                ans = min(ans , cost)  
if ans > S:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

for num_book in range(1, N + 1):
    ans = []
    for i in itertools.combinations(list_N, num_book):
        #print(i)
        temp = 0
        for j in range(1, M + 1):
            sum_line = sum([s[i[k]][j] for k in range(num_book)])
            if sum_line < X:
                break
            temp += 1
            if temp == M:
                #print(i)
                ans.append(sum([s[i[k]][0] for k in range(num_book)]))
    if len(ans) != 0:
        break
if len(ans)==0:
    print(-1)
else:
    print(min(ans))

Submission status: Wrong Answer

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

# print(A)
# print(C)

ans_money = float('inf')
# ans_algorythm = None
for i in range(2**N):
    bit = bin(i)[2::]
    # print("bit: {}".format(bit))
    tmp_money = 0
    tmp_algorythm = [0] * M
    for j, b in enumerate(bit[::-1]):
        if b == '1':
            tmp_money += C[j]
            for k, c in enumerate(A[j]):
                tmp_algorythm[k] += c
    # print("tmp_money: {}, tmp_algorythm: {}".format(tmp_money, tmp_algorythm))
    if len(list(filter(lambda x: x < X, tmp_algorythm))) == 0:
        ans_money = min(tmp_money, ans_money)
        break

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

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
a=[0]*n
sum=[0]*m
sm=0
for i in range(n):
    l=list(map(int,input().split()))
    a[i]=l

for i in range(n):
    sm+=a[i][0]
    for j in range(m):
        sum[j]+=a[i][j+1]

for i in range(m):
    if sum[i]<x:
        print(-1)
        exit()

a.sort()

for i in reversed(range(n)):
    k=0
    for j in range(m):
        if sum[j]-a[i][j+1]>=x:
            k+=1
    if k==m:
        for j in range(m):
            sum[j]-=a[i][j+1]
        sm-=a[i][0]


print(sm)