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())
ca = [list(map(int, input().split())) for _ in range(n)]

pair = []

for c1 in range(2):
    for c2 in range(2):
        for c3 in range(2):
            for c4 in range(2):
                for c5 in range(2):
                    for c6 in range(2):
                        for c7 in range(2):
                            for c8 in range(2):
                                for c9 in range(2):
                                    for c10 in range(2):
                                        for c11 in range(2):
                                            for c12 in range(2):
                                                pair.append([c1, c2, c3, c4, c5,c6, c7, c8, c9, c10, c11,c12])

zenkingaku = []
for pattern in pair:
    rikaido = [0 for _ in range(m)]
    kingaku = 0
    _pattern = pattern[:n]
    for ca_i, p in enumerate(_pattern):
        if p == 1:
            kingaku += ca[ca_i][0]
            for ca_j in range(1, m):
                rikaido[ca_j] += ca[ca_i][ca_j] 

    for ca_j in range(1, m):
        if rikaido[ca_j] < x:
            kingaku = -1

    if kingaku == -1:
        continue

    zenkingaku.append(kingaku)

if not zenkingaku:
    zenkingaku = [-1]
print(min(zenkingaku))

Submission status: Wrong Answer

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

def main():
    N, M, X = map(int, input().split())
    C = [0] * N
    A = []
    for n in range(0, N):
        l = input().split()
        C[n] = int(l[0])
        A.append([int(i) for i in l[1:]])

    min_cost = sum(C) + 1
    for i in range(N):
        for comb in itertools.combinations(range(N), i):
            canAchive = True
            for m in range(M):
                r = 0
                for n in comb:
                    r += A[n][m]
                if (r < X):
                    canAchive = False
                    break
            if (canAchive):
                cost = sum([C[n] for n in comb])
                min_cost = min(min_cost, cost)

    if (min_cost <= sum(C)):
        print(min_cost)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ca = [[]]*n

for i in range(n):
    ca[i] = list(map(int, input().split()))

min = 10**15

for i in range(2**n):
    bin_i = bin(i)
    sum = 0
    point = [0]*m
    flag = 1
    l = len(bin_i)-2
    for j in range(l):
        if bin_i[-j-1] == "1":
            sum += ca[j][0]
            for k in range(m):
                point[k] += ca[j][k+1]

    for j in range(m):
        if point[j] >= x:
            pass
        else:
            flag = 0

    if flag:
        if sum <= min:
            min = sum

print(min)

Submission status: Wrong Answer

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

min_cost = float('inf')
for i in range(1, M + 1):
    t_list = list(map(np.array, combinations(books, i)))
    for combi in t_list:
        # print(combi)
        counts = np.array([0 for _ in range(M + 1)])
        for nums in combi:
            counts += nums
        ok = True
        for num in counts[1:]:
            if num < X:
                ok = False
                break
        if ok:
            min_cost = min(min_cost, counts[0])
if min_cost == float('inf'):
    print(-1)
else:
    print(min_cost)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
c = {}
a = []

for i in range(n):
    a.append(list(map(int, input().split())))
    c[i] = a[-1].pop(0)

c_sorted = sorted(c.items(), key=lambda x:x[1], reverse=True)

results = [0] * m

for i in range(n):
    for j in range(m):
        results[j] += a[i][j]

if min(results) < x:
    print(-1)
else:
    ans = 0
    for i in range(n):
        ans += c[i]
    for i in range(n):
        results_new = [0] * m
        for j in range(m):
            results_new[j] = results[j] - a[c_sorted[i][0]][j]
        if min(results_new) >= x:
            ans -= c_sorted[i][1]
            results = results_new
        else:
            pass
    print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    N, M, X = map(int, input().split())
    L = []*M
    ans = 10000000000
    for i in range(N):
        L.append(tuple(map(int, input().split())))

    for i in range(2 ** N):
        s = 0
        C = [0]*M
        for j in range(N):
            if (i >> j) & 1:
                C = [a+b for (a, b) in zip(C, L[j])]
                s += L[j][0]
        CC = len([c for c in C if c >= X])
        if CC == M:
            ans = min(ans, s)
    print(-1 if ans == 10000000000 else ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

CA = []
for i in range(N):
    s = input()
    CA.append(np.fromstring(s, np.int64, sep=" "))

CA = np.asarray(CA)
C = CA[:, :1]
A = CA[:, 1:]

def loop(i, x, total):
    if i == N:
        if (x >= X).all():
            return total
        else:
            return np.inf

    return min(loop(i+1, x, total), loop(i+1, x+A[i], total+C[i]))

ans = loop(0, np.zeros_like(A[0]), 0)
if ans == np.inf:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x=list(map(int, input().split()))
ca=[]
for i in range (n):
    ca.append(list(map(int, input().split())))
u=[0]*m
for j in range (m):
    for i in range (n):
        u[j]+=ca[i][j+1]
det=1
for y in range (m):
    if u[y]<x:
        det=0
if det==0:
    print(-1)
else:
    cost=1300000
    for z in range(2**n-1):
        bi=[0]*n
        for p in range(n):
            if z>=2**(n-1-p):
                bi[p]=1
                z=z-2**(n-1-p)
        v=[0]*m
        for i in range(n):
            if bi[i]==1:
                for j in range(m): 
                    v[j]+=ca[i][j+1]
        de=1
        for y in range (m):
            if v[y]<x:
                de=0
        if de==1:
            cc=0
            for q in range (n):
                cc+=ca[q][0]*bi[q]
            if cc<cost:
                cost=cc
    print(cost)

Submission status: Wrong Answer

Solution code:
import math

(n, m, x) = [int(s) for s in input().split()]

b = []
for _ in range(0, n):
    d = [int(s) for s in input().split()]
    d.append(sum(d[1:]) / d[0])
    b.append(d)


b = sorted(b, key=lambda x: x[-1], reverse=True)

#v = math.factorial(12) // math.factorial(0)

min = 0
x_l = [0] * m
r_l = [False] * m
for c in b:
    for (i, a) in enumerate(c[1:-1]):
        x_l[i] += a
        if x_l[i] >= x:
            r_l[i] = True

    f = set(r_l)
    min += c[0]
    if len(f) == 1 and r_l[0]:
        break
else:
    min = -1

ans = min

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(2**n):
    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(" "))
A=[]
for i in range(n):
  A.append(list(map(int,input().split(" "))))

minprice=[]
for i in range(1, m+1):
  for j in range(n):
    mini = j
    for k in range(j,n):
      if A[mini][i] > A[k][i]:
        mini = k
    temp = A[mini]
    A[mini] = A[j]
    A[j] = temp

  x_m= A[0][1:m+1]
  p_m=A[0][0]
  for j in range(1,n):
    if min(x_m) < x:
      for k in range(m):
          x_m[k]+=A[j][k+1]
      p_m += A[j][0]
  if min(x_m) >= x:
      minprice.append(p_m)
  
if minprice:
    print(min(minprice))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def sum_list(l1, l2):
  return [i+j for i, j in zip(l1, l2)]

def judge(l):
  for i in l[1:]:
    if i < X:
      return False
  return True

N, M, X = map(int, input().split())
array = []
zeros = [0]*M
for i in range(N):
  row = [j for j in map(int, input().split())]
  array.append(row)
  zeros = sum_list(zeros, row)

for z in zeros[1:]:
  if z < X:
    print(-1)
    exit()

ret = float('inf')
for i in range(2**N):
  arr = [0]*(M+1)
  cost = 0
  for j in range(N):
    if i >> j & 1:
      arr = sum_list(arr, array[j])
  if judge(arr):
    ret = min(ret, arr[0])
    
print(ret)

Submission status: Wrong Answer

Solution code:
import itertools

n,m,x=[int(i) for i in input().split(" ")]
l=[]
for i in range(n):
    l.append([int(i) for i in input().split(" ")])

l.sort()
result=0

for i in range(1,n+1):
    for pair in itertools.combinations(l,i):
        sumL=[0]*m
        for p in pair:
            for j in range(m):
                sumL[j]+=p[j+1]
        flag=True
        for j in range(m):
            if sumL[j]<x:
                flag=False
                break
        if flag:
            # print(pair,sumL)
            print(sum([i[0] for i in pair]))
            exit(0)
            break
print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

CA = []
for i in range(N):
    s = input()
    CA.append(np.fromstring(s, np.int16, sep=" "))

CA = np.asarray(CA)
C = CA[:, :1]
A = CA[:, 1:]

def loop(i, x, total):
    if i == N:
        if (x >= X).all():
            return total
        else:
            return np.inf

    return min(loop(i+1, x, total), loop(i+1, x+A[i], total+C[i]))

ans = loop(0, np.zeros_like(A[0]), 0)
if ans == np.inf:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
possibility = False

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

result = 10**6

for i in range(2 ** N):
    cost = 0
    rikai = [0] * M
    for j in range(N):
        if (i >> j & 1):
            cost += C[j]
            for k in range(M):
                rikai[k] += A[j][k]
    if sum(map(lambda x: x >= X, rikai)) == M:
        possibility = True
        result = min(cost, result)

print(result if possibility else -1)

Submission status: Wrong Answer

Solution code:
def main():
    [n, m, x] = [int(i) for i in input().split(" ", 3)]
    u = {i: 0 for i in range(m)}
    s = 0
    is_succeeded = False
    books = sorted([[int(j) for j in input().split(" ")]
                    for i in range(n)], key=lambda x: sum(x[1:]))
    books.reverse()
    for b in books:
        s += b.pop(0)
        for j, k in enumerate(b):
            u[j] += k
        if x <= min(list(u.values())):
            is_succeeded = True
            break
    print(s if is_succeeded else "-1")


main()

Submission status: Wrong Answer

Solution code:
pi = 3.1415926

############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n,m,x = invr()
nums = []
ans = [10**6]

for i in range(n):
    nums.append(inlt())
    
def cal(ins):
    aaa = [0 for i in range(m)]
    cost = 0
    for i in ins:
        cost += nums[i][0]
        
        for index,j in enumerate(nums[i][1:]):
            aaa[index] += j

    for i in range(m):
        if aaa[i] < x:
            return 10**6
    else:
        return cost
    
def printCombination(arr, n, r): 
      
    # A temporary array to  
    # store all combination 
    # one by one 
    data = [0]*r; 
  
    # Print all combination  
    # using temprary array 'data[]' 
    combinationUtil(arr, data, 0,  
                    n - 1, 0, r); 
  
# arr[] ---> Input Array 
# data[] ---> Temporary array to 
#         store current combination 
# start & end ---> Staring and Ending 
#             indexes in arr[] 
# index ---> Current index in data[] 
# r ---> Size of a combination  
# to be printed  
def combinationUtil(arr, data, start,  
                    end, index, r): 
                          
    # Current combination is ready  
    # to be printed, print it 
    if (index == r):
        ins = []
        for j in range(r): 
            ins.append(data[j])

        result = cal(ins)
        if result < ans[0]:
            ans[0] = result 
        return; 
  
    # replace index with all 
    # possible elements. The 
    # condition "end-i+1 >=  
    # r-index" makes sure that  
    # including one element at 
    # index will make a combination  
    # with remaining elements at  
    # remaining positions 
    i = start;  
    while(i <= end and end - i + 1 >= r - index): 
        data[index] = arr[i]; 
        combinationUtil(arr, data, i + 1,  
                        end, index + 1, r); 
        i += 1; 
    
arr = [i for i in range(n)]
for i in range(1,n + 1):
    printCombination(arr,n,i)

print(ans[0] if ans[0] < 10**6 else -1)

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
        for k in j:
            a=0
            p=0
            for i in range(1,m+1):
                r[i-1]+=k[i]
                a+=r[i-1]>=x
            if a==m:
                for c in j:
                    p+=c[0]
                print(p)
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N,M,X = map(int,input().split())
C = []
for _ in range(N):
  C.append([int(v) for v in input().split()])
Ca,Aa = [],[]
for k in range(1,N):
  for v in combinations(C,k):
    tmp = [0]*(M+1)
    for v2 in v:
      for i,v3 in enumerate(v2):
        tmp[i]+=v3
    isOK = True
    for v2 in tmp[1:]:
      if v2 < X:
        isOK = False
        break
    if isOK:
      #print(tmp)
      Ca.append(tmp[0])
if len(Ca) == 0:
  print(-1)
else:
  print(min(Ca))

Submission status: Wrong Answer

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

minprice=[]
for i in range(1, m+1):
  for j in range(n):
    mini = j
    for k in range(j,n):
      if A[mini][i] > A[k][i]:
        mini = k
    temp = A[mini]
    A[mini] = A[j]
    A[j] = temp

  print(A)
  x_m= A[0][1:m+1]
  p_m=A[0][0]
  for j in range(1,n):
    if min(x_m) < x:
      for k in range(m):
          x_m[k]+=A[j][k+1]
      p_m += A[j][0]
  if min(x_m) >= x:
      minprice.append(p_m)
  
if minprice:
    print(min(minprice))
else:
    print(-1)

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):
    aa = []
    flag = True
    for j in range(M):
      s = sum([ca[i][j] for i in v])
      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:
import sys
import numpy as np

read = sys.stdin.read

n, m, k = map(int, input().split())
ca = np.array(read().split(), dtype=np.int64).reshape([n,m+1])

ans = 10**8

for i in range(2**n):
    b = np.array(list(format(i,'0'+str(n)+'b')), dtype=np.int64)
    print(b)
    d = ca[b == 1].sum(axis=0)
    print(d)
    if np.all(d[1:] >= k):
        ans = min(ans, d[0])

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

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
money=0
lis=[0]+[-x]*m
al = []
ans=[]
mkr=0
for _ in range(n):
    li = list(map(int,input().split()))
    al.append(li)
    for i in range(len(li)):
        lis[i] += li[i]
for i in lis:
    if i<0:
        mkr=1
if mkr==1:
    print(-1)
else:
    al.sort(reverse=True)
    for i in range(n):
        mkr=0
        lis2=lis.copy()
        for j in range(m):
            if lis[j]<al[i][j]:
                mkr=1
                break
            else:
                lis2[j]-=al[i][j]
        if mkr==0:
            lis=lis2.copy()
    print(lis[0])

Submission status: Wrong Answer

Solution code:
def main():
    from sys import stdin
    import itertools
    n,m,x = map(int,stdin.readline().rstrip().split())
    mat = []
    for _ in range(n):
        temp = list(map(int,stdin.readline().rstrip().split()))
        mat.append(temp)
    
    sum = []
    for i in range(n+1):
        for l in itertools.combinations(mat,i):
            temp = [0]*m
            for j in l:
                for k in range(m):
                    temp[k]+=j[k]
            sum.append(temp)
    
    sum.sort(key=lambda x: x[0])
    for l in sum:
        ans = -1
        flag = True
        for j in l[1:]:
            if j < x:
                flag = False
                break
        
        if flag:
            ans=l[0]
            break
    
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
from itertools import combinations

def skill(m, l, x):
    ans = pow(10, 9)
    rikai = [0 for _ in range(m)]
    for i in range(m):
        cl = combinations(range(n), i+1)
        for c in cl:
            cost = 0
            rikai = [0 for _ in range(m)]
            for j in c:
                cost += l[j][0]
                for k in range(m):
                    rikai[k] += l[j][k+1]
            flag = 0
            for k in range(m):
                if rikai[k] < x:
                    flag = 1
                    break
            if flag == 0 and cost < ans:
                ans = cost
            # print(c, cost, rikai)
    if ans != pow(10, 9):
        print(ans)
    else:
        print(-1)

n, m, x = [int(i) for i in input().split()]
l = []
for _ in range(n):
    l.append([int(i) for i in input().split()])

skill(m, l, x)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np
def main():
    n, m, x = map(int, input().split())
    lst = []
    for _ in range(n):
        tmp = list(map(int, input().split()))
        lst.append(tmp)
    
    bango = [i for i in range(n)]
    k = 1
    while k <= n:
        combs = combinations(bango, k)
        for comb in combs:
            
            algo = np.zeros(m)
            kingaku = 0
            for c in comb:
                algo += np.array(lst[c][1:])
                kingaku += lst[c][0]
            
            if (algo >= x).all():
                print(kingaku)
                return
        k += 1
    print('-1') 
main()

Submission status: Wrong Answer

Solution code:
import itertools

def main():
    N,M,X = list(map(int, input().split(' ')))
    
    inputs = []
    for _ in range(N):
        inputs.append(list(map(int, input().split(' '))))
        
    Ci = [s[0] for s in inputs]
    Aij = [s[1:] for s in inputs]
    
    # print(Ci, Aij)
    
    indexs = [i for i in range(N)]
    
    com = []
    for n in range(1,N+1):
        com.extend(list(itertools.combinations(
        indexs, n)))
    
    
    minimum = 100000000
    isOK = False
    for inds in com:
        # A,B,C=0,0,0
        skills = [m for m in range(M)]
        MONE = 0
        for ind in inds: # (0,1)
            power = Aij[ind]
            skills = [power[i] + skills[i] for i in range(M)]
            MONE += Ci[ind]
        
        skills = [n >=X for n in skills]
        # print(skills, inds, MONE)
        if False not in skills:
            isOK = True
            minimum = min(minimum, MONE)
    
    if isOK is True:
        print(minimum)
    else:
        print('-1')
    
    
            
    

main()

Submission status: Wrong Answer

Solution code:


def main():
    N,M,X  = map(int, input().split()) 
    C = []
    for _ in range(N):
        c=list(map(int, input().split()))
        C.append(c)
    
    min = -1

    for i in range(2 ** N):
        total = 0
        bag = []
        OK = False
        for j in range(N):  
            if ((i >> j) & 1):  
                bag.append(C[j])
        sumlist=[0]*M
        for j in range(len(bag)):
            for k in range(M):
                sumlist[k] += bag[j][k]
        for k in range(M-1):
            if(sumlist[k+1] < X):
                OK = False
                break
            else:
                OK = True
        if OK and (min==-1 or min > sumlist[0]):
            min = sumlist[0]

    print (min)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import combinations

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

ans = 10 ** 9
for i in range(1, n+1):
    combination = combinations(range(n), i)
    for comb in combination:
        init = np.zeros(m+1)
        for ind in list(comb):
            init = init + np.array(lis[ind])
        if np.amin(init[1:]) >= x:
            ans = min(ans,init[0])
    if ans < 10**9:
      print(int(ans))
      exit()
      
print(-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)

# 1 ✕ N
N, M, X = list(map(int, input().rstrip().split()))

# # N ✕ M (2D array)
A = list(input().rstrip().split() for _ in range(N))

ans = 1e9
for bit in range(2 ** N):
    total = 0
    array = [0 for _ in range(0, M)]

    for i in range(N):
        if bit & 1 << i:
            total += int(A[i][0])
            for j in range(0, M):
                array[j] += int(A[i][j])

    found = True
    for i in range(M):
        if array[i] < X:
            found = False

    if found:
        ans = min(ans, total)

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

Submission status: Wrong Answer

Solution code:
import itertools

N, M, X = [int(i) for i in input().split()]
CA = [] # (C, A)
A = []
for i in range(N):
    c, *a = [int(i) for i in input().split()]
    CA.append((c, a))

min_c = 12 * 10**5 + 1
for x in range(1, N+1):
    for ca in itertools.combinations(CA, x):
        tmp_a = [0 for _ in range(M)]
        tmp_c = 0
        for s in ca:
            tmp_c += s[0]
            tmp_a = [tmp_a[j]+s[1][j] for j in range(M)]
        print(tmp_a)
        if min(tmp_a) >= X:
            min_c = min(min_c, tmp_c)

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

Submission status: Wrong Answer

Solution code:
n,m,x = list(map(int,input().split()));
price = [0]*n;
rikai = [[0]*m for i in range(n)];

for i in range(n) :
    ca = list(map(int,input().split()));
    price[i] = ca[0];
    for j in range(m) :
        rikai[i][j] = ca[j+1];

ans = sum(price);
able = 0;
for i in range(2**n) :
    allrikai = [0]*m;
    nowprice = 0;
    for j in range(n) :
        if (i>>j)&1 :
            nowprice += price[j];
            for k in range(m) :
                allrikai[k] += rikai[j][k];
    check = 1;
    for j in range(m) :
        if allrikai[j] < x :
            check = 0;
            break;
        else :
            able = 1;
    if check and nowprice < ans :
        ans = nowprice;

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from functools import reduce
n, m, x = map(int, input().split())
a = []

def aryadd(ary):
    a = []
    for i in zip(*ary):
        a.append(sum(i))
    return a

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

ans = 10**9
for i in range(2, n+1):
    for j in combinations(a, i):
        sm = aryadd(j)
        if len(list(filter(lambda y: y >= x, sm[1:]))) >= m:
            if ans >= sm[0]:
                ans = sm[0]

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

Submission status: Wrong Answer

Solution code:
def sum_list(l1, l2):
  return [i+j for i, j in zip(l1, l2)]

def judge(l):
  for i in l[1:]:
    if i < X:
      return False
  return True

N, M, X = map(int, input().split())
array = []
zeros = [0]*M
for i in range(N):
  row = [j for j in map(int, input().split())]
  array.append(row)
  zeros = sum_list(zeros, row)

for z in zeros[1:]:
  if z < X:
    print(-1)
    exit()

ret = float('inf')
for i in range(2**N):
  arr = [0]*M
  cost = 0
  for j in range(N):
    if i >> j & 1:
      arr = sum_list(arr, array[j])
  if judge(arr):
    ret = min(ret, arr[0])
    
print(ret)

Submission status: Wrong Answer

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

A = [0]*M
for i in range(N):
    for k in range(M):
        A[k] += CA[i][k+1]
for i in range(M):
    if A[i] < X:
        print('-1')
        exit() 

A = [0]*M
price = 0
CA.sort(key=lambda CA:(CA[0]))
for i in range(N):
    for k in range(M):
        A[k] += CA[i][k+1]
        price += CA[i][0]
    if all(A[l] >= X for l in range(M)):
        print(price)
        break

Submission status: Wrong Answer

Solution code:
N, M, X = list(map(int, input().split()))
conditions = [str(bin((2**N + i) & (2**(N+1) - 1)))[3:] for i in range(2**N)]
Q = [list(map(int, input().split())) for i in range(N)]
ans = -1
for c in conditions:
    res = [0]*M
    for i in range(N):
        if c[i] == '1':
            for j in range(M):
                res[j] += Q[i][j]
    failed = False
    for i in range(1, M):
        if res[i] >= X:
            continue
        else:
            failed = True
    if failed:
        continue
    else:
        if ans == -1:
            ans = res[0]
        else:
            ans = min(ans, res[0])

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import combinations

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

ans = 10 ** 9
for i in range(1, n+1):
    combination = combinations(range(n), i)
    for comb in combination:
        init = np.zeros(m+1)
        for ind in list(comb):
            init = init + np.array(lis[ind])
        if np.amin(init[1:]) >= x:
            ans = min(ans,init[0])
    if ans < 10**9:
      print(int(ans))
      exit()
      
print(-1,-1,-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 = 1000000
    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 == 1000000:
        print(-1)
    else:
        print(min)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

C_total_min = -1
for ci in range(N):  # 組み合わせの数
    for seq in itertools.combinations(range(N), ci): # 組み合わせのリスト
        C_total = 0
        A_total = [0] * M
        for ni in seq:
            C_total += C[ni]
            A_total = [A_total[ai] + A[ni][ai] for ai in range(M)]

        # 判定
        flag = True
        for ai in range(M):
            if A_total[ai] < X:
                flag = False
        if flag: # Trueなら
            if C_total_min == -1:
                C_total_min = C_total
            elif C_total_min > C_total:
                C_total_min = C_total
            else:
                pass

print(C_total_min)

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
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]
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]
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:
N, M, X = map(int, input().split())
Q = []
B = [0] * N
C = [0] * (M + 1)
flag = True
MIN = -1
for i in range(N):
  Q.append(list(map(int, input().split())))
  
for i in range(2 ** N):
  B = [0] * N
  C = [0] * (M + 1)
  flag = True
  for j in range(N):
    B[j] = (i >> j) & 1
    
  for j in range(N):
    if B[j] == 1:
      for k in range(M + 1):
        C[k] += Q[j][k]
  for j in range(1, M + 1):
    if C[j] < X:
      flag = False
    if flag == True:
      if MIN == -1 or MIN > C[0]:
        MIN = C[0]
      
print(MIN)