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

res=10**7

for i in range(2**n-1):
	money=0
	under=[0]*m
	
	for j in range(n):
		if i>>j&1:
			money+=CA[j][0]
			for k in range(m):
				under[k]+=CA[j][k+1]
		
		if min(under)>=x:
			res=min(res,money)

if res==10**7:
	print("-1")
else:
	print(res)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

res = float('inf')
for r in range(N):
    for c in combinations(range(N), r):
        skills = [0] * M
        price = 0
        for i in c:
            price += books[i][0]
            for j, a in enumerate(books[i][1:]):
                skills[j] += a
        if all(skill >= X for skill in skills):
            res = min(res, price)

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m,x=map(int,readline().split())
    c=[]
    a=[]
    for i in range(n):
        ca=list(map(int,readline().split()))
        c.append(ca[0])
        a.append(ca[1:])

    print(c)
    print(a)
    
    min_res=float("inf")
    for i in range(1<<n):
        output=[]
        res=0
        rikaido=[0]*m
        for j in range(n):
            if(i>>j)&1:
                output.append(j)
        for j in output:
            res+=c[j]
            for k in range(m):
                rikaido[k]+=a[j][k]
        for k in range(m):
            if rikaido[k]<x:
                break
        else:
            min_res=min(res,min_res)

    if min_res==float("inf"):
        min_res=-1

    print(min_res)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools

n, m, x = map(int, input().split())
c = [None] * n
a = [None] * n
for i in range(n):
    aa = list(map(int, input().split()))
    c[i] = aa[0]
    a[i] = aa[1:]

ans = 100000000000
for k in range(n):
    for cmb in itertools.combinations(range(n), k):
        d = [0] * m
        cost = 0
        for cm in cmb:
            cost += c[cm]
            for i in range(m):
                d[i] += a[cm][i]

        f = True
        for i in range(m):
            if d[i] < x:
                f = False
                break
        if f:
            ans = min(ans, cost)

if ans == 100000000000:
    ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  N, M, X = map(int, input().split())
  ans = float('inf')
  table = []
  for i in range(N):
    table.append(list(map(int, input().split())))
                 
  for i in range(2 ** N):
    tmp = [0] * (M+1)
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(M+1):
              tmp[k] += table[j][k]
    for l in range(1, len(tmp)):
      if tmp[l] < X:
        break
    else:
      if ans > tmp[0]:
        ans = tmp[0]
  if ans != float('inf'):
    print(ans)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
INF = 10**18

n, m, x = map(int, input().split())
costs = []
a = []
for i in range(n):
    cost, *tmp = map(int, input().split())
    costs.append(cost)
    a.append(tmp)

ans = INF
for i in range(1 << n):
    cost = 0
    ms = [0] * m
    for j in range(n):
        if (i >> j) & 1 == 1:
            cost += costs[j]
            for k in range(m):
                ms[k] += a[j][k]
    can_learn = True
    for j in range(m):
        if ms[j] < x:
            can_learn = False
            break
    if can_learn:
        print(cost, ms)
        ans = min(ans, cost)

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

Submission status: Wrong Answer

Solution code:
N,M,X = map(int,input().split())
books = [list(map(int,input().split())) for _ in range(N)]
digit = "0"+str(N)+"b"
ans = float("INF")
for i in range(2**N):
    flags = list(format(i,digit))
    rikaid = [0]*(M)
    cost = 0
    for j in range(N):
        if flags[j] == "1":
            cost += books[j][0]
            for k in range(M):
                rikaid[k] += books[j][k]
    for r in rikaid:
        if r < X:
            break
    else:
        ans = min(ans,cost)
if ans == float("INF"):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
 
n,m,x = LI()
a = [LI() for i in range(n)]
result = 1200000
for i in range(1 << n):
    c = 0
    val = [0]*m
    for j in range(n):
        if(i & (1 << j)):
            c += a[j][0]
            for k in range(m):
                val[k] += a[j][k+1]
    f = True
    for j in range(m):
        if(val[j] < x):
            f = False
            break
    
    if(f):
        if(result > c):
            result = c

if(result == 1200000):
    print(-1)
else:
    print(result)

Submission status: Wrong Answer

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

from itertools import combinations


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, M, X = map(int, input().split())
    CA = [[] for _ in range(N)]
    for n in range(N):
        CA[n] = list(map(int, input().split()))

    COSTS = []
    for n in range(N):
        for c in combinations(CA, n):
            SUM = [0 for _ in range(M)]
            COST = 0
            for ca in c:
                COST += ca[0]
                for m in range(M):
                    SUM[m] += ca[m+1]
            if all(list(map(lambda x: x >= X, SUM))):
                COSTS.append(COST)
    if COSTS:
        print(min(COSTS))
        return
    print(-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

res = float('inf')
for r in range(N):
    for c in combinations(range(N), r):
        skills = [0] * M
        price = 0
        for i in c:
            price += books[i][0]
            for j, a in enumerate(books[i][1:]):
                skills[j - 1] += a
        if all(skill >= X for skill in skills):
            res = min(res, price)

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

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
min_c = float('inf')
l = []
for i in range(n):
    ns = list(map(int, input().split()))
    l.append(ns)
for i in range(2 ** n):
    flag = True
    a = bin(i)[2:].zfill(n)
    for j in range(m):
        s = 0
        for index, b in enumerate(a):
            if b == '1':
                s += l[index][j]
        if s < x:
            flag = False
            break
    if flag:
        min_c = min(min_c, sum(l[i][0] for i in range(n) if a[i] == '1'))
if min_c == float('inf'):
    print(-1)
else:
    print(min_c)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,x = map(int,input().split())
c = []
for i in range(n):
  a = [int(i) for i in input().split()]
  c.append(a)
  
c = np.array(c)
ans = float('inf')
for i in range(1,2**n):
  chk = [0]*m
  cost = 0
  for j in range(n):
    if (i>>j)&1 == 1:
      cost += c[j][0]
      chk += c[j][1:]
  if min(chk) >= x:
    ans = min(ans,cost)
    
print(ans)

Submission status: Wrong Answer

Solution code:
cin = open(0).read().strip().split('\n')
n,m,x = map(int, cin[0].split(' '))
books = []
for i in cin[1:]:
    books.append(tuple(map(int, i.split(' '))))

for i in range(2**n):
    ret = [0] * m
    money = 0
    for j in range(n):
        if i >> j & 1:
            for mi in range(m):
                ret[mi] += books[j][1+mi]
            money += books[j][0]
    if min(ret) >= x:
        print(money)
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
C, A = [], []
ans = 100000
exist = False
for n in range(N):
    li = list(map(int, input().split()))
    C.append(li[0])
    A.append(li[1:])
for b in range(1 << N):
    amount = 0
    understand = [0] * M
    for n in range(N):
        if (b >> n) & 1 == 1:
            amount += C[n]
            for m in range(M):
                understand[m] += A[n][m]
    achieve = True
    for m in range(M):
        if X > understand[m]:
            achieve = False
    if achieve:
        exist = True
        ans = min(ans, amount)
if exist:
    print(ans)
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)]

maxa = [0 for i in range(m)]
for i in range(n):
    for j in range(m):
        maxa[j] += ca[i][j+1]
ans = 10**6
for i in range(m):
    if maxa[i] < x:
        ans = -1
        break

#print(maxa)

def sankousyo(l):
    if len(l) == n:
     #   print(l)
        global ans
        kingaku = 0
        maxa_k = [0 for i in range(m)]
        for i in range(n):
            if l[i] == 1:
                for j in range(m):
                    maxa_k[j] += ca[i][j+1]
        for i in range(m):
            if maxa_k[i] < x:
                kingaku = -1
                break
        if kingaku != -1:
            for i in range(n):
                if l[i] == 1:
                    kingaku += ca[i][0]
            ans = min(ans,kingaku)
   #     print(kingaku)
    else:
        sankousyo(l+[0])
        sankousyo(l+[1])
    
if ans == 10**6:
    sankousyo([])

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import defaultdict
import collections
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

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

ans = mod
for i in range(2 ** n):
    alg = defaultdict(int)
    switch = [0] * n
    for j in range(n):
        if((i >> j) & 1):
            switch[j] = 1
    for k in range(n):
        for l in range(m + 1):
            if switch[k] == 1:
                alg[l] += ca[k][l]
    for y in alg:
        if y != 0:
            if x > alg[y]:
                break
        if y == m - 1:
            ans = min(ans, alg[0])

if ans == mod:
    print("-1")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
INF = 1001001
N, M, X = map(int, input().split())
C, A = [], []
for i in range(N):
    _c = list(map(int, (input().split())))
    _a = _c[1:]
    _c = _c[0]
    A.append(_a)
    C.append(_c)
ans = INF
for b in range(1<<N):
    money = 0
    point = [0]*M
    for i in range(N):
        if (b>>i)&1:
            money += C[i]
            for j in range(M):
                point[j] += A[i][j]
    for j in range(M):
        if point[j] < X:
            break
    else:
        ans = min(ans, money)
if ans == INF:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

from itertools import combinations


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, M, X = map(int, input().split())
    CA = [[] for _ in range(N)]
    for n in range(N):
        CA[n] = list(map(int, input().split()))

    for n in range(N):
        COSTS = []
        for c in combinations(CA, n):
            SUM = [0 for _ in range(M)]
            COST = 0
            for ca in c:
                COST += ca[0]
                for m in range(M):
                    SUM[m] += ca[m+1]
            if all(list(map(lambda x: x >= X, SUM))):
                COSTS.append(COST)
        if COSTS:
            print(min(COSTS))
            return
    print(-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
c=[]
a=[]
for _ in range(n):
  ca=list(map(int,input().split()))
  c.append(ca[0])
  a.append(ca[1:])
ans=12*pow(10,5)
for i in range(2**n):
  rikai=[0]*m
  kin=0
  for j in range(n):
    if ((i>>j) & 1):#立っているビットのところで処理が走る
      for k in range(m):
        rikai[k]+=a[j][k]
      kin+=c[j]
  if min(rikai)>=x:
    ans=min(ans,kin)
print(ans if ans<12*pow(10,5) else -1)

Submission status: Wrong Answer

Solution code:
n,m,co=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
c=2**n
ans=10**10
for i in range(c):
  li=[]
  a=0
  for j in range(n):  
      if ((i >> j) & 1):  
        li.append(l[j])
        a+=l[j][0]
  z=[0]*m
  for k in range(len(li)):
    for kk in range(m):
      z[kk]+=li[k][kk]
  if min(z)>co-1:
    ans=min(ans,a)
if ans==10**10:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = f_inf
    for pattern in product([0, 1], repeat=n):
        A = [0 for _ in range(m)]
        cost = 0
        for idx, p in enumerate(pattern):
            if p == 1:
                cost += C[idx][0]
                for i in range(m):
                    A[i] += C[idx][i]

        for a in A:
            if a < x:
                break
        else:
            res = min(res, cost)

    if res == f_inf:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

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

ans = -1

for i in range(2 ** N):
    A = [0] * M
    buy = 0
    for j in range(N):
        if (i >> j) & 1:
            buy += ca[j][0]
            for k in range(1, M + 1):
                A[k - 1] += ca[j][k]

    for i in range(M):
        if A[i] < X:
            break

        if i == M - 1:
            if ans == -1:
                ans = buy
        else:
            ans = min(ans, buy)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,co=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
c=2**n
ans=10**10
for i in range(c):
  li=[]
  a=0
  for j in range(n):  
      if ((i >> j) & 1):  
        li.append(l[j])
        a+=l[j][0]
  z=[0]*m
  for k in range(len(li)):
    for kk in range(m):
      z[kk]+=li[k][kk]
  if min(z)>co-1:
    ans=min(ans,a)
if ans==10**10:
  print(-1)
  quit()
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
from itertools import product
li=[]
ans=10**9
for i in range(n):
    a=list(map(int,input().split()))
    li.append(a)
for p in product([0, 1], repeat = n):
    cnt = [0 for _ in range(m)]
    price=0
    for i in range(n):
        if p[i]==1:
            price+=li[i][0]
            for j in range(m):
                cnt[j]+=li[i][j]
    if min(cnt)>=x:
        ans=min(ans,price)
if ans==10**9:
    print("-1")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]
true_buy = float("inf")
for i in range(2**n):
  buy = []
  buy_sum = 0
  for j in range(n):
    if (i>>j) & 1:
      buy.append(ca[j])
      buy_sum += ca[j][0]
  for k in range(m):
    gain = 0
    for l in range(len(buy)):
      gain += buy[l][k]
    if gain < x:
      buy_sum = float("inf")
  true_buy = min(buy_sum,true_buy)
if true_buy == float("inf"):
  print(-1)
else:
  print(true_buy)

Submission status: Wrong Answer

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

ans = -1

def calc_score(data, score):
    for i in range(m):
        score[i] += data[i]

def judge_score(score):
    for i in range(m):
        if score[i] < x:
            return False
    
    return True

for i in range(2 ** n):
    score = [0] * m
    price = 0
    for j in range(n):
        if i >> j & 1:
            calc_score(data[j], score)
            price += data[j][0]
    if judge_score(score):
        if ans == -1:
            ans = price
        else:
            ans = min(ans, price)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M,X = LMIIS()
    books = []
    for _ in range(N):
        books.append(LMIIS())
    min_cost = 12 * 10**5
    for i in range(2**N):
        algo = [0]*M
        cost = 0
        for j in range(N):
            if i & (2**j):
                cost += books[j][0]
                for k in range(M):
                    algo[k] += books[j][k+1]
        if min(algo) < X:
            continue
        min_cost = min(min_cost,cost)
    print(min_cost if min_cost != 12*10**5 else -1)

        



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

def tobin(x,n):
    return format(x,'b').zfill(n)

ans = 1e10
for i in range(2**n):
    b = format(i,'b').zfill(n)
    # print(b)
    buf = [0 for i in range(m)]
    temp = 0
    for j in range(n):
        if b[j]=="1":
            temp += books[j][0]
            for k in range(1,m+1):
                buf[k-1] += books[j][k]
        else:
            continue
    # print(buf)
    flag = True
    for val in buf:
        if val < x:
            flag = False

    if flag and ans > temp:
        ans = temp
    else:
        continue

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,x=map(int,input().split())
c=[]
A=[]
for _ in range(n):
    l = [int(i) for i in input().split()]
    c.append(l[0])
    A.append(l[1:])
c=np.array(c)
A=np.array(A)
ans = 20*10**5
bits =[]

for i in range(2 ** n):
    bag = []
    for j in range(n):
        if ((i >> j) & 1): 
            bag.append(j)
    ar = np.sum(A[bag],axis=0)
    if all(ar>=x):
        temp = np.sum(c[bag])
        ans = min(ans,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m, x = MAP()
arr = [LIST() for _ in range(n)]
c = [arr[i][0] for i in range(n)]
a = [arr[i][1:] for i in range(n)]
ans = inf
for i in range(1, n):
    cmb = list(combinations(range(n), i))
    for lst in cmb:
        tmp = [0 for _ in range(m)]
        cst = 0
        for idx in lst:
            cst += c[idx]
            for j in range(m):
                tmp[j] += a[idx][j]
        flag = True
        for j in range(m):
            if tmp[j] < x:
                flag = False
        if flag:
            ans = min(ans, cst)
if ans == inf:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#
# abc167 c
#
import sys
from io import StringIO
import unittest
from collections import deque


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3 10
60 2 2 4
70 8 7 9
50 2 3 9"""
        output = """120"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 3 10
100 3 1 4
100 1 5 9
100 2 6 5"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """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"""
        output = """1067"""
        self.assertIO(input, output)


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

    ans = float("inf")
    for bit in range(1 << N):
        S = [0]*(M+1)
        for i, ca in enumerate(CA):
            if (1 << i) & bit == 1 << i:
                S = list(map(sum, zip(S, ca)))
        for s in S[1:]:
            if s < X:
                break
        else:
            ans = min(ans, S[0])

    if ans == float("inf"):
        ans = -1

    print(ans)


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

    b = deque()
    ans = dfs(0, b)
    if ans == float("inf"):
        ans = -1

    print(ans)


def dfs(n, B):
    if n == N:
        S = [0]*(M+1)
        for i, ca in enumerate(CA, 1):
            if i in B:
                S = list(map(sum, zip(S, ca)))
        for s in S[1:]:
            if s < X:
                return float("inf")
        else:
            return S[0]

    ans = float("inf")
    B.append(n+1)
    tmp = dfs(n+1, B)
    ans = min(ans, dfs(n+1, B))
    B.pop()
    ans = min(ans, dfs(n+1, B))

    return ans


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

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

p_list = list(itertools.permutations(range(N)))
cost_list = []
for p in p_list :
    sum_list = [0]*(M+1)
    for i in p :
        for m in range(M+1) :
            sum_list[m] += B[i][m]
        if X <= min(sum_list[1:]) :
            break
    if min(sum_list[1:]) < X :
        print(-1)
        exit()
    cost_list.append(sum_list[0])

# print(cost_list)
print(min(cost_list))

Submission status: Time Limit Exceeded

Solution code:
import itertools,copy
cost = 0
N,M,X = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(N)]
combi = itertools.permutations(range(N),N)
sumx = [0]*M
sumfx = [0]*M
for j in range(N):
    for i in range(M):
        sumx[i]+=ca[j][i+1]
        if sumx[i]>=X:
            sumfx[i]=1
    cost += ca[j][0]
ans = cost
if sum(sumfx) != M:
    print(-1)
    
else:
    for a in combi:
        x = copy.copy(sumx)
        fx = copy.copy(sumfx)
        c = cost
        for i in range(len(a)):
            for j in range(1,M+1):
                x[j-1] -= ca[a[i]][j]
                if x[j-1]<X:
                    fx[j-1] = 0

            if sum(fx)!=M:
                break
            else:
                c -= ca[a[i]][0]
                ans = min(c,ans)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
cost = 10**12
N,M,X = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(N)]
combi = itertools.permutations(range(N),N)
for a in combi:
    x = [0]*M
    fx = [0]*M
    c = 0
    for i in range(len(a)):
        for j in range(1,M+1):
            x[j-1] += ca[a[i]][j]
            if x[j-1]>=X:
                fx[j-1] = 1
        c += ca[a[i]][0]
        if c>cost:
            break
        if sum(fx)==M:
            break
    if sum(fx) == M:
        cost = min(c,cost)
print(cost if cost !=10**12 else -1)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

N,M,X = map(int,input().split())
ca = ([list(map(int,input().split())) for _ in range(N)])
ca = np.array(ca)
combi = itertools.permutations(range(N),N)
sumX = sum(ca)[1:]
sumcos = sum(ca)[0]
cost = sumcos
if sum(sumX>=X)<M:
    print(-1)
else:
    for a in combi:
        x = sum(ca)[1:]
        fx = np.array([0]*M)
        c = sumcos
        for i in range(len(a)):
            x -= ca[a[i]][1:]
            c -= ca[a[i]][0]
            if sum(x>=X)<M:
                break
            else:
                cost = min(c,cost)
    print(cost)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
cost = 10**12
N,M,X = map(int,input().split())
ca = ([list(map(int,input().split())) for _ in range(N)])
ca = np.array(ca)
combi = itertools.permutations(range(N),N)
for a in combi:
    x = np.array([0]*M)
    fx = np.array([0]*M)
    c = 0
    for i in range(len(a)):
        x += ca[a[i]][1:]
        c += ca[a[i]][0]
        if c>cost:
            break
        if sum(x>=X)==M:
            break
    if sum(x>=X)==M:
        cost = min(c,cost)
print(cost if cost !=10**12 else -1)

Submission status: Time Limit Exceeded

Solution code:
def mincuota(listas, N, M, X):
  for i in range(1, M+ 1):
    skill = 0
    for j in range(N):
      skill+= listas[j][i]
    if(skill < X):
      return -1
  else:
    newcuotas = []
    for i in range(N):
      newlistas = listas[:i]+ listas[i+ 1:]
      if(mincuota(newlistas, N- 1, M, X) != -1):
        newcuotas.append(mincuota(newlistas, N- 1, M, X))
    if(newcuotas == []):
      cuota = 0
      for i in range(N):
        cuota+= listas[i][0]
      return cuota
    else:
      return min(newcuotas)
  
N, M, X = map(int, input().split())
listas = []
for i in range(N):
  listas.append(list(map(int, input().split())))

  
print(mincuota(listas, N, M, X))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N,M,X=map(int,input().split())
C=[]*N


A=[]
seq=[]
for i in range(N):
    A.append(list(map(int,input().split())))
    seq.append(i)
rikai=[0 for i in range(M+1)]

min=-1
count=0


for i in range(1,N+1):
    kumi=list(itertools.permutations(seq,i))

    for j in kumi:

        for n in list(j):

            for k in range(M+1):
                rikai[k]=A[n][k]+rikai[k]

        for k in range(1,len(rikai)):
            if(X<=rikai[k]):

                count=count+1

            rikai[k]=0
        if(count==len(rikai)-1):

            if(rikai[0]<min or min==-1):
                min=rikai[0]

        rikai[0]=0
        count=0
print(min)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations
from collections import Counter
ct = Counter()
Ass = []
N, M, X = map(int, input().split())
for i in range(N):
	As = list(map(int, input().split()))
	ct[i] = As[0]
	Ass.append(As[1:])

C = []
for z in range(M):	
	B = []
	for i in range(N):
		B.append(Ass[i][z])
	D = []
	for i in range(1, N+1):
		l = list(combinations(range(N), i))
		
		for j in l:
			s = 0
			for jj in j:
				s += B[jj]
			if s >= X:
				D.append(j)
	C.append(D)

cand = []
for i in C[0]:
	flag=True
	for j in C[1:]:
		if i not in j:
			flag=False
			break
	if flag:
		cand.append(i)
ans = 10**9


for i in cand:
	s = 0
	for j in i:
		s+= ct[j]
	if s < ans:
		ans = s

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

Submission status: Time Limit Exceeded

Solution code:
def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y
 
N, M, X = map(int, input().split())
price = -1
 
L = []
a = []
c = []
suit =[]
for i in range(M+1):
    a.append(0)
    
for i in range(N):
    text = input().split()
    L.append(intlist(text))
 
def buy(x,y):
    
    if x + y <= N:
        
        for i in range(0,M+1):
            
            a[i] += L[x+y-1][i]
            
       
        if x + y == N:
            score = a[1:len(a)]
            
            if min(score) >= X:
                suit.append(a.copy())
                
        elif x + y != N:
            buy(x+1,y)
            for i in range(0,M+1):
                a[i] -= L[x+y][i]
           
            notbuy(x,y+1)
 
 
def notbuy(x,y):
   
    if x + y <= N:
        
        if x + y == N:
            score = a[1:len(a)]
            if min(score) >= X:
                suit.append(a.copy())
                    
             
        elif x + y != N:
            buy(x+1,y)
            for i in range(0,M+1):
                a[i] -= L[x+y][i]
            notbuy(x,y+1)    
 
def textbook(x,y):
    buy(x+1,y)
    for i in range(0,M+1):
        a[i] -= L[x+y][i]
    notbuy(x,y+1)
 
textbook(0,0)
 
b = []
 
if suit != []:
    for i in range(len(suit)):
        for j in range(len(suit)-1):
            if suit[j] > suit[j+1]:
                b = suit[j]
                suit[j] = suit[j+1]
                suit[j+1] = b
    price = suit[0][0]
 

print(price)