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:
# coding:utf-8
n, m, x = map(int, input().split())

book = [list(map(int, input().split())) for _ in range(n)]
all_book = [0] * m

for i in range(0, n):
    for j in range(0, m):
        all_book[j] += book[i][j]

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

price = all_book[0]
# print(price)

for i in range(0, n):
    if all(item >= x for item in all_book):
        price = (min(price, all_book[0]))
    else:
        print(price)
        exit()
    for j in range(0, m):
        all_book[j] -= book[i][j]

Submission status: Wrong Answer

Solution code:
def list_add(li1, li2):
    return list(map(sum,zip(li1,li2)))
N, M, X = map(int, input().split(" "))
list = []
for i in range(N):
    list.append([int(i) for i in input().split(" ")])
list.sort()
price = 0
knowledge = []
for i in range(N):
    price = price + list[i][0]
    if i == 0:
        knowledge = list[0][1: M + 1]
    else:
        tmp2 = [x + y for (x, y) in zip(knowledge, list[i][1:M+1])]
        knowledge = tmp2
    # 全部足しても足りないとき
    if i == N - 1 and min(knowledge) < X:
        print(-1)
        exit()
    # 目標を超えたとき
    if min(knowledge) >= X:
        for j in range(i, -1, -1):
            searchList = [x - y for (x, y) in zip(knowledge, list[j][1: M + 1])]
            if min(searchList) >= X:
                knowledge = searchList
                price = price - list[j][0]
        print(price)
        exit()

Submission status: Wrong Answer

Solution code:
import itertools

lis=list(map(int,input().split()))
N=lis[0]
M=lis[1]
X=lis[2]
book=[[0]*(M+1)]*N

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

buy=list(itertools.product('YN', repeat=N))


for i in buy :
    Buy=list(i)
    rikai=[0]*M
    cost=0
    for j in range(N):
        if(Buy[j]=="Y"):
            cost+=book[j][0]
            rikai=[x+y for (x, y) in zip(rikai,book[j])]
    if(min(rikai)>=X):
        Cost.append(cost)
if(len(Cost)>=1):
    print(min(Cost))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# coding:utf-8
n, m, x = map(int, input().split())

book = [list(map(int, input().split())) for _ in range(n)]
all_book = [0] * m

for i in range(0, n):
    for j in range(0, m):
        all_book[j] += book[i][j]

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

price = all_book[0]
print(price)

for i in range(0, n):
    if all(item >= x for item in all_book):
        price = (min(price, all_book[0]))
    else:
        print(price)
        exit()
    for j in range(0, m):
        all_book[j] -= book[i][j]

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools as iters

n, m , x = list(map(int, input().split()))
c = np.empty((n, 1))
a = np.empty((n, m))

for i in range(n):
  ca = list(map(int, input().split()))
  c[i] = ca[0]
  for idx in range(m):
    a[i][idx] = ca[idx+1]

max_score = sum(a)

if 1 in (max_score < x):
  print(-1)
  exit()

min_price = 10 ** 6

for i in range(n):
  pairs = iters.combinations(range(n), i+1)
  for pair in pairs:
    price = 0
    check = np.zeros((1, m))
    for idx in pair:
      price += c[idx]
      check += a[idx]
    if 1 not in (check < x):
      if price < min_price:
        min_price = price

print(int(min_price))

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

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

L.sort(key=lambda x: x[0])
s = float('inf')
r = False

for i in range(1, N + 1):
    C = combinations(range(0, N), i)
    for c in C:
        _s = 0
        t = [0 for _ in range(M)]
        for _c in c:
            _s += L[_c][0]
            for k in range(M):
                t[k] += L[_c][k + 1]
        for _t in t:
            if _t < X:
                break
        else:
            r = True
        if r and _s < s:
            s = _s
if r:
    print(s)
else:
    print(-1)

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')
permutations = []
for i in range(M + 1):
    if i == 0:
        permutations.extend([None])
    else:
        permutations.extend(list(map(np.array, combinations(books, i))))


for permutation in permutations:
    if permutation is None:
        if X == 0:
            min_cost = min(min_cost, 0)
            break
        else:
            continue
    sums = np.sum(permutation, axis=0)
    ok = True
    for skill in sums[1:]:
        if skill >= X:
            ok = True
        else:
            ok = False
            break
    if ok:
        min_cost = min(min_cost, sums[0])
if min_cost == float('inf'):
    print(-1)
else:
    print(min_cost)

Submission status: Wrong Answer

Solution code:
import itertools
 
N,M,X = map(int, input().split())
C_A = []
for _ in range(N):
    C_A.append(list(map(int, input().split())))
# print(C_A)
 
min_price = 10**5 * 12 
rikaido = [0 for _ in range(M)]
possible = 0
for i in itertools.product([0,1], repeat=N):
    price_rikaido = [sum(C_A[j][k]*i[j] for j in range(N)) for k in range(M+1)]
    # print(i)
    # print(price_rikaido)
    flag = 1
    for l in range(M):
        if price_rikaido[l+1] <X:
            flag = 0
            break
    if flag and (min_price > price_rikaido[0]):
        min_price = price_rikaido[0]
        possible = 1
        
if possible:
    print(min_price)
else:
    print(-1)

Submission status: Wrong Answer

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

for i in range(N):
  kl = sum(D[i])-D[i][0]
  if kl >= X:
    ans[0] += D[i][0]
    for j in range(1,M+1):
      ans[j] += D[i][j]
    flg = 0
    for k in range(1,len(ans)):
      if ans[k] >= X:
        flg += 1
    if flg == M:
      print(ans[0])
      exit()

Submission status: Wrong Answer

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

c = []
for i in range(n):
  c.append([int(j) for j in input().split()])

ans = []

for bit in range(2 ** len(c)):
  u = []
  for j in range(len(c)):
    if (bit >> j) & 1:
      u.append(c[j])

  f = False
  for h in range(1,m+1):
    mm = 0
    for z in u:
      mm += z[h]

    if mm < x:
      break
    elif mm >= x:
      f = True
  
  if f:
    jj = 0
    for i in u:
      jj += i[0]
    ans.append(jj)

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

Submission status: Wrong Answer

Solution code:
import numpy as np

if __name__ == '__main__':
    T = input().split()
    N = int(T[0])
    M = int(T[1])
    X = int(T[2])
    price = np.zeros(N)
    qual = np.zeros((N, M))
    for n in range(N):
        t = input().split()
        price[n] = int(t[0])
        qual[n, :] = np.array([int(m) for m in t[1:]])

    ind = np.argsort(np.sum(qual, axis=1) / price)[::-1]
    pay = 0
    sums = np.zeros(M)
    exit = 0
    for i in range(N):
        pay += price[ind[i]]
        sums += qual[ind[i], :]
        if np.all(sums >= X):
            print(int(pay))
            exit = 1
            break
    if exit == 0:
        print(-1)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
#a_L = list(map(int,input().split()))
import itertools
#print(L)
a_L = []
c_L = []

import numpy as np


        

for i in range(n):
    tmp= list(map(int,input().split()))
    c = tmp[0]
    tmpL = tmp[1:]
    a_L.append(tmpL)
    c_L.append(c)
print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
import sys
N,M,X=map(int, input().split())

i=0
lst = []
while i < N:
    m = map(int, input().split())
    lst.append(list(m))
    i+=1
arr = np.array(lst)

#Xに至らなかったとき
if np.min(np.sum(arr[:,1:], axis=0)) < X:
    print(-1)
    sys.exit()
data = arr[:,1:]
res = 1000000
for i in range(1,N+1):
    for conbi in itertools.combinations(lst, i):
        arrx = np.array(conbi)
        if np.min(np.sum(arrx[:,1:], axis=0)) >= X:
            if res > np.sum(arrx[:,0]):
                res = np.sum(arrx[:,0])
    if res != 1000000:
        print(res)
        break

Submission status: Wrong Answer

Solution code:
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float('INF')
for i in range(2**N):
    bit = np.array([[i>>j&1 for j in range(N)]]).T
    temp = np.sum(CA*bit,axis=0).tolist()
    temp2 = []
    temp2.append(temp)
    for money,*x in temp2:
        for y in x:
            if y<10:
                break
        else:
            ans = min(ans,money)
print(ans if ans !=float('INF') else -1)

Submission status: Wrong Answer

Solution code:
import itertools
N,M,X=map(int,input().split())
ans=10**6
List=[]
for _ in range(N):
  List.append([int(i) for i in input().split()])
for i in range(0,N):
  for j in itertools.combinations(range(N),i+1):
    tmp=[0]*(M+1)
    for k in j:      
      for l in range(M+1):
        tmp[l]+=List[k][l]
    if len([m for m in tmp[1:] if m>=X])==M:
      ans=min(ans,tmp[0])
if ans==10**6:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:


def main():
    NMX = list(map(int,input().split()))

    CA = []

    for i in range(NMX[0]):
        CA.append(list(map(int,input().split())))

    CA.sort()
    CA.reverse()

    # print(CA)

    smA =[0] * (NMX[1]+1)

    for n in range(NMX[0]):
        for m in range(NMX[1]+1):
            smA[m] += CA[n][m]

    # print(smA)

    for n in range(NMX[0]):
        pre = []

        J = True


        for m in range(NMX[1]+1):
            if m == 0:
                pre.append(smA[m]-CA[n][m])
            else:
                pre.append(smA[m] - CA[n][m])

                if smA[m] - CA[n][m] < NMX[2]:
                    # print("yes")
                    J = False
                    break

        # print(smA)
        if J:
            smA = pre
        else:
            continue


    JU = True
    for i in range(len(smA)):
        if i == 0:
            continue
        else:
            if smA[i] < NMX[2]:
                JU = False

    if JU:
        print(smA[0])
    else:
        print("-1")


    # print(smA)

if __name__ == '__main__':
    main()

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)]
all_list = list(itertools.product([0,1], repeat=n))
ans_flag = False

final_answer = float("inf")
for i in range(len(all_list)):
  anslist = [0]*m
  anscost = 0
  for j in range(n):
    if all_list[i][j] == 1:
      anscost += ca[j][0]
      for k in range(1,m):
        anslist[k] += ca[j][k]

  flag = True
  for l in range(1,m):
    if anslist[l] < x:
      flag = False
  if flag:
    ans_flag = True
    final_answer = min(final_answer,anscost)
if ans_flag:
  print(final_answer)
else:
  print("-1")

Submission status: Wrong Answer

Solution code:
import itertools

def check(arr,t):
    for i in arr:
        if i < t:
            return False
    return True

N,M,X = list(map(int,input().split()))
l = []
for _ in range(N):
    l.append(list(map(int,input().split())))
buy_bit = list(itertools.product([0,1], repeat=N))
mi = 99999999999999999
for pattern in buy_bit:
    learned = [0 for _ in range(M)]
    total = 0
    for idx,bit in enumerate(pattern):
        if bit == 1:
            total += l[idx][0]
            for learned_id in range(M):
                learned[learned_id] += l[idx][learned_id]
    if total < mi and check(learned,X):
        mi = total
if mi == 99999999999999999:
    print(-1)
else:
    print(mi)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import numpy as np

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

result = []
for n in range(2 ** N):
    ii = [0] * N
    for i in range(N):
        if (n >> i) & 1:
            ii[i] = 1
    # print(ii)
    tmp = [0] * (M + 1)
    for j in range(len(ii)):
        if ii[j] == 1:
            tmp = (np.array(tmp) + np.array(C[j])).tolist()
    result.append(tmp)


def ex(array):
    for i in array:
        if i < X:
            return False
    return True


min_value = -1
for r in result:
    if ex(r):
        min_value = min(min_value, r[0])
print(min_value) if min_value != -1 else print(-1)

Submission status: Wrong Answer

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

I = []

for i in range(n):
  I.append(list(map(int, input().split())))
    
ans = 1000000
  
for i in range(1<<n):
  u = [0] * m
  c = 0
  for j in range(n):
    if (i>>j) % 2 == 1:
      for k in range(m):
        u[k] += I[j][k+1]
      c += I[j][0]
        
  flag = 1
  for e in u:
    if e < x:
      flag = 0
      
  if min(u) < x:
    continue
  else:
    ans = min(ans, c)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
import sys
N,M,X=map(int, input().split())

i=0
lst = []
while i < N:
    m = map(int, input().split())
    lst.append(list(m))
    i+=1
arr = np.array(lst)

#Xに至らなかったとき
if np.min(np.sum(arr[:,1:], axis=0)) < X:
    print(-1)
    sys.exit()
data = arr[:,1:]
for i in range(1,N+1):
    res = 1000000
    for conbi in itertools.combinations(lst, i):
        arrx = np.array(conbi)
        if np.min(np.sum(arrx[:,1:], axis=0)) >= X:
            if res > np.sum(arrx[:,0]):
                res = np.sum(arrx[:,0])
    if res != 1000000:
        print(res)
        break

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
m = int(a[1])
x = int(a[2])

bo =  []
for i in range(n):
    bo.append(input().split())
# bo = [int(i) for i in [j for j in sbo] ]

cost = 999999999999
pat = []
for i in range(2 ** n):
    tp = []
    for j in  range(n):
        if ((i >> j) & 1):
            tp.append(bo[j])
    pat.append(tp)

# print(pat)

for i in pat:
    ef = [0] * (m)
    tcost = 0
    for j in i:
        tcost += int(j[0])
        for k in range(1,m):
            ef[k] += int(j[k])
    flg = True
    for l in range(1,m):
        if ef[l] < x:
            flg = False
    if flg:
        cost = min(cost,tcost)

if cost == 999999999999:
    print(-1)
else :
    print(cost)

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 if i >= x]
        if len(l_ans) > m:
            print(l_ans[0])
            exit()
        else:
            continue
print("-1")

Submission status: Wrong Answer

Solution code:
import itertools

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


kakaku = 100001
combinations = []
for n in range(1, N+1):
    combinations += list(itertools.combinations(range(N), n))

for pair in combinations:
    hantei = True
    for m in range(M):
        total = 0
        for i in pair:
            total += CA[i][m+1]
        if X <= total:
            continue
        else:
            hantei = False
            break
    if hantei:
        kingaku = 0
        for i in pair:
            kingaku += CA[i][0]
        kakaku = min(kakaku, kingaku)
    else:
        continue

if kakaku == 100001:
    print(-1)
else:
    print(kakaku)

Submission status: Wrong Answer

Solution code:
import itertools

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

min_price = 10**5 * 12 
rikaido = [0 for _ in range(M)]

for i in itertools.product([0,1], repeat=N):
    price_rikaido = [sum(C_A[j][k]*i[j] for j in range(N)) for k in range(M+1)]
    print(i)
    print(price_rikaido)
    flag = 1
    for l in range(M):
        if price_rikaido[l+1] <X:
            flag = 0
            break
    if flag and (min_price > price_rikaido[0]):
        min_price = price_rikaido[0]
        
if min_price == 10**5 * 12 :
    print(-1)
else:
    print(min_price)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, x = [int(e) for e in input().split()]
    CA = [[int(e) for e in input().split()] for i in range(n)]

    ans = 10 ** 6
    for i in range(1, 2 ** 12 + 1):
        bs = format(i, f'0{n}b')

        cs = 0
        Sm = [0] * m
        for i in range(n):
            if bs[i] == '1':
                cs += CA[i][0]
                for mi in range(m):
                    Sm[mi] += CA[i][mi + 1]

        if all(sm >= x for sm in Sm):
            ans = min(cs, ans)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
N, M, X = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
li = []
for i in range(N+1):
    for j in itertools.combinations(range(N), i):
        sm = [0] * (M+1)
        for k in j:
            for l in range(M+1):
                sm[l] += a[k][l]
        if all(y >= X for y in sm[1:M+1]):
            li.append(sm[0])
if li == []:
    print(-1)
else:
    print(min(li))
print(li)

Submission status: Wrong Answer

Solution code:
import itertools
N, M, X = [int(_) for _ in input().split()]
B = []
for i in range(N):
    B.append([int(_) for _ in input().split()])
l = [i for i in range(N)]
NUM = (10**5) * 12 + 1
ans = NUM
for i in range(1, M+1):
    C = itertools.combinations(l, i)
    for c in C:
        amount = 0
        U = [0 for i in range(M)]
        for k in range(i):
            amount += B[c[k]][0]
            for j in range(M):
                U[j] += B[c[k]][j+1]
        if min(U) >= X:
            ans = min(ans, amount)
if ans == NUM:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

D = np.array([])
for i in range(N):
    D = np.append(D,list(map(int, input().split())))
D = D.reshape(N,M+1)

S = D.sum(axis=0)

if all(s >= X for s in S[1:]):
    D = D[np.argsort(D[:, 0])[::-1]]
    for i in range(N):
        if all(j>=X for j in (S - D[i])[1:]):
            S = S - D[i]
    print(int(S[0]))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


def main():
    N, M, X = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    money = 10**6
    rikai = [0] * M

    for i in range(N):
        a = combinations(range(N), i + 1)
        for s in a:
            tmp_money = 0
            rikai = [0] * M
            for x in s:
                tmp_money += A[x][0]
                for m in range(M):
                    rikai[m] += A[x][m + 1]
            if min(rikai) >= X:
                money = min(money, tmp_money)
    if money == 10 ** 6:
        print(-1)
    else:
        print(money)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

def main():  #startline-------------------------------------------
    n, m, x = map(int, input().split())
    ca = [list(map(int, input().split())) for i in range(n)]
    ans = float("inf")
    subsc = []#選ばれている本
    for i in range(1 << n):
        for j in range(n):
            if (i >> j)&1:
                subsc.append(ca[j])
        flag = True
        cost = 0
        if len(subsc) == 0:
            continue
        unst = 0  #理解度
        for j in range(1,m):
            for k in range(len(subsc)):
                unst += subsc[k][j]
            if unst < x:
                flag = False
            unst = 0
        for j in range(len(subsc)):
            cost += subsc[j][0]
        if flag:
            ans = min(ans, cost)
        flag = True
        cost = 0
        subsc = []
    if ans == float("inf"):
        ans = -1
    print(ans)

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

Submission status: Wrong Answer

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

    ans = [0] * m
    price = 0
    c = sorted(c, key=lambda x: sum(x[1:]) / x[0], reverse=True)

    for i in c:
        price = price + i[0]
        p = i[1:]
        for i in range(len(ans)):
            ans[i] += p[i]

        if all([i >= x for i in ans]):
            # print(ans)
            print(price)
            break
    if not all([i >= x for i in ans]):
        print(-1)

resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M, X = map(int, input().split(" "))

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

info = np.array(info)
info = info[np.argsort(info[:, 0])]
dp = np.zeros([N, M])
nedan = np.zeros([N])

for i in range(N):
    for j in range(i, N):
        if np.any(dp[i] < X):
            dp[i] += info[j, 1:]
            nedan[i] += info[j, 0]
        else:
            break

OK = [np.all((d) >= X) for d in dp]
if np.any(OK):
    print(int(np.min(nedan[OK])))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.array(A)
C = np.array(C)
result = -2
A_sum = A.sum(axis=0)
if A_sum.min() < X:
    result = -1
else:
    s = (-C).argsort()
    As = A[s]
    Cs = C[s]
    score = np.copy(A.sum(axis=0))
    money = C.sum()
    for a, c in zip(As, Cs):
        if (score - a).min() >= X:
            score -= a
            money -= c
    result = money
print(result)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int,input().split())
ca = [(list(map(int,input().split())))]
print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
N, M, K = map(int, input().split())
Q = [np.asarray(input().split(), dtype=int) for i in range(N)]
min_cost = 10**9
def dfs(cost, C, depth=0):
  global min_cost
  if depth == N:
    return
  if (C >= K).all():
    min_cost = min([cost, min_cost])
    return
  dfs(cost+Q[depth][0], C + Q[depth][1:], depth+1)
  dfs(cost, C, depth+1)
  
dfs(0, np.zeros(M))
    
print(min_cost) if min_cost != 10**9 else print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
(n, m, x) = tuple(map(int, input().split(" ")))
ca = [list(map(int, input().split(" "))) for i in range(n)]
c = -1
for i in range(n):
    itr = itertools.combinations(ca, i + 1)
    for v in itr:
        cv = np.array(v).sum(axis=0)
        if (cv[1:m] >= x).all() and (c == -1 or cv[0] < c):
            c = cv[0]
print(c)

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(list(conb))

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

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

Submission status: Wrong Answer

Solution code:
import itertools

def get_target_list(source):
    targets = []
    for size in range(1, len(source) + 1):
        for x in itertools.combinations(source, size):
            targets.append(x)
    return targets

paramN, paramM, paramX = list(map(lambda x: int(x), input().split(' ')))
targets = get_target_list([list(map(lambda x: int(x), input().split(' '))) for i in range(paramN)])

price_sum = 10000000000
for books in targets:
    ps = 0
    tmp = [i for i in range(paramM)]
    for book in books:
        ps += book[0]
        for i, x in enumerate(book[1:]):
            tmp[i] += x
    if len(list(filter(lambda y: y < paramX, tmp))) == 0:
        price_sum = min(price_sum, ps)

if price_sum == 10000000000:
    print(-1)
else:
    print(price_sum)

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:
import numpy as np
n, m, x = map(int, input().split())
ca_list = [list(map(int, input().split())) for _ in range(n)]

r_list = [x] * m
ans = 0
for i in range(n):
    if sum(r_list) == 0: break
    max_e = 0
    min_m = 0
    select = []
    index = -1
    for j, a in enumerate(ca_list):
        tmp = a[1:]
        for k, v in enumerate(tmp):
            if tmp[k] > r_list[k]: tmp[k] = r_list[k]
        if sum(tmp) / a[0] > max_e:
            max_e = sum(tmp) / a[0]
            min_m = a[0]
            select = tmp
            index = j
    ans += min_m
    r_list = list(np.array(r_list) - np.array(select))
    ca_list.pop(index)
if sum(r_list) != 0: ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import numpy as np

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

result = []
for n in range(2 ** N):
    ii = [0] * N
    for i in range(N):
        if (n >> i) & 1:
            ii[i] = 1
    # print(ii)
    tmp = [0] * (M + 1)
    for j in range(len(ii)):
        if ii[j] == 1:
            tmp = (np.array(tmp) + np.array(C[j])).tolist()
    result.append(tmp)


def ex(array):
    for i in array:
        if i < X:
            return False
    return True


min_value = sys.maxsize
for r in result:
    if ex(r):
        min_value = min(min_value, r[0])
print(min_value) if min_value != sys.maxsize else print(-1)

Submission status: Wrong Answer

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

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

    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]))

    while loopflag:
        loopflag = False
        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]
                loopflag = True
                califlag[w] = False
                ans -= cali[w][0]

    return 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:
import numpy as np
import itertools

N, M, X = map(int, input().split())
a = [list(map(int, input().split())) for l in range(N)]
a = np.array(a)
sum_a = np.array([0 for _ in range(M+1)])
a = sorted(a, key=lambda x:x[0])

# for row in a:
#     sum_a = sum_a + row
#     if all([i >= X for i in sum_a[1:]]):
#         break

min_tmp = None
min_money = np.inf
for i in range(M):
    p = itertools.permutations(a, i)
    for j in p:
        sum_tmp = np.array([0 for _ in range(M+1)])
        for k in j:
            sum_tmp = sum_tmp + k
        if all([i >= X for i in sum_tmp[1:]]):
            if min_money > sum_tmp[0]:
                min_tmp = j
                min_money = sum_tmp[0]
        
if min_money != np.inf:
    print(min_money)
else:
    print(-1)