Problem:


Score : 300 points

Problem

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

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

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

Constraints

All values in input are integers.

1\leq N, M\leq 12

1\leq X\leq 10^5

1\leq C_i \leq 10^5

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

120

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

Sample Input 2

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

Sample Output 2

-1

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

Sample Input 3

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

Sample Output 3

1067



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


Sample output:
120

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import combinations_with_replacement

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

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M):
  if sums[i] < X:
    OK = False
    break

if OK == False:
  print(-1)
else:
  As = []
  for A in combinations_with_replacement(range(0, N), r=M):
    As.append(tuple(set(A)))
  As = list(map(list, set(As)))
  min_ = sums[0]
  for i in As:
    mini_CA = []
    for j in i:
      mini_CA.append(CA[j])
    mini_CA = np.array(mini_CA)
    OK2 = True
    sums = np.sum(mini_CA,axis=0)
    for k in range(1,M):
      if sums[k] < X:
        OK2 = False
        break
    if OK2 == True and sums[0] < min_:
      min_ = sums[0]
  print(min_)

Submission status: Wrong Answer

Solution code:
from operator import add
N,M,X = map(int, input().split())
tmp = [list(map(int,list(input().split()))) for i in range(N)]
c= []
a = [[] for i in range(N)]
result = []
for i in range(N):
    c.append(tmp[i][0])
    a[i].extend(tmp[i][1:])

for bit in range(1 << (N)):
    suma = [0] * M
    disc = [X] * M
    c4i = []
    rsum = 0
    for i in range(N):
        if (bit & (1<<i)):
            # ここでとった要素を一個づつ見る
            suma = map(add,suma,a[i])
            c4i.append(i)
    suma = list(suma)
    print(c4i)
    print(suma,disc)
    print(suma>=disc)
    if suma >= disc:
        for t in c4i:
            rsum = rsum + c[t]
        result.append(rsum)
print(result)
if result:
    print(min(result))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ALL = np.zeros((1, M+1))
for n in range(N):
  CA = np.array([ int(i) for i in input().split() ])
  ALL = np.vstack([ALL, CA])

A  = ALL.sum(axis=0)
cost =2**100
#ALL = np.sort(ALL, axis=0)

for n in range(2**N):
    a = str(bin(n))[2:]
    b = N-len(a)
    c = np.array(list('0'*b+a)).astype('bool')
    #print(c)
    ALL2 = ALL[1:]
    check = ALL2[c].sum(axis=0)
   
    if (check[1:] < X).sum() < 1:
      if  cost >  check[0]:
        cost = check[0]


if cost == 2**100:
  cost = -1
print(cost)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int,input().split())
a=[]
b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
c=[]
for i in range(N):
    a.append(input().split())
    c.append(0)

check=0
ans=-1
for i in range(1,(2**N)-1):
    b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    check=0
    for j in range(N):
        if 0x01 & (i >> j):
            for n in range(M+1):
                b[n] = b[n] + int(a[j][n])
        for k in range(1,M):
            if b[k] < X:
                check=1
                break
    if check==0:
        #print(ans)
        if ans == -1 or ans > b[0]:
            ans = b[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ALL = np.zeros((1, M+1))
for n in range(N):
  CA = np.array([ int(i) for i in input().split() ])
  ALL = np.vstack([ALL, CA])

A  = ALL.sum(axis=0)
cost =2**100
#ALL = np.sort(ALL, axis=0)


if (A[1:] < X).sum() > 0:
  print(-1)
else:
  for n in range(2**N):
    a = str(bin(n))[2:]
    b = N-len(a)
    c = np.array(list('0'*b+a)).astype('bool')
    #print(c)
    ALL2 = ALL[1:]
    check = ALL2[c].sum(axis=0)
   
    if (check[1:] < X).sum() == 0:
      if  cost >  check[0]:
        cost = check[0]

  print(cost)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N, M, X = map(int, input().split())

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

INF = 10**9
ans = INF
for s in range(0, 1 << N):
    smart = [0] * M
    cost_sum = 0
    for i in range(N):
        if (s >> i) % 2 == 0:
            continue
        cost_sum += C[i]
        for j in range(M):
            smart[j] += A[i][j]
    ok = True
    for j in range(M):
        if smart[j] < X:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x=list(map(int,input().split()))
ans=10**6
A=[list(map(int,input().split())) for i in range(n)]
for i, _ in enumerate(A,1):
  for j in itertools.combinations(A,r=i):
    B=list(zip(*j))
    
    C=[0]*(m+1)
    for m in range(m+1):
      C[m]=sum(B[m])
    if len([i for i in C[1:] if i>=x ])==m:
      ans=min(ans,C[0])
print(ans) if ans!=10**6 else print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = sorted(l)
l = np.array(l)
ans = np.sum(l, 0)[0]
ans_s = np.sum(l, 0)
if np.any(ans_s[1:] < x):
    print(-1)
    exit()
count = 0
for i in range(1, m + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ALL = np.zeros((1, M+1))
for n in range(N):
  CA = np.array([ int(i) for i in input().split() ])
  ALL = np.vstack([ALL, CA])

A  = ALL.sum(axis=0)
cost =99999999999999
#ALL = np.sort(ALL, axis=0)


if (A[1:] < X).sum() > 0:
  print(-1)
else:
  for n in range(2**N):
    a = str(bin(n))[2:]
    b = N-len(a)
    c = np.array(list('0'*b+a)).astype('bool')
    #print(c)
    ALL2 = ALL[1:]
    check = ALL2[c].sum(axis=0)

    #print(check[0])
    # print(check[1:])
    if (check[1:] < X).sum() == 0:
      if  cost >=  check[0]:
        cost = check[0]

  print(cost)

Submission status: Wrong Answer

Solution code:
import numpy as np  # NumPyモジュールをインポートする
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  # 全部intに変換

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  # 全部intに変換
    I[i] = val2

seq = [i for i in range(val[0])]  # 組み合わせを考える
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            # print("xxx=", j)
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

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

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = sorted(l)
l = np.array(l)
ans = np.sum(l, 0)[0]
ans_s = np.sum(l, 0)
if np.any(ans_s[1:] < x):
    print(-1)
    exit()
count = 0
for i in range(1, m + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
            print(int(ans))
            exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import itertools
import sys
import copy
N, M, X  = map(int, input().split())
money = []
A = []
ans = 0
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
    
def run(lis, num, A, X, M):
    ans = sum(lis)
    tmp_ans = sum(lis)
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[lis.index(j)][i]
            if tmp >= X:
                count += 1
        if sum(list(team)) < tmp_ans and count == M:
            ans = sum(list(team))
            tmp_ans = sum(list(team))
    if not ans == sum(lis):
        print(ans)
        sys.exit()
for i in range(2, N+1):
    run(money, i, A, X, M)

print(-1)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n,m,x = MI()
a = []
c = []
for i in range(n):
  dd = LI()
  c.append(dd[0])
  dd = dd[1:]
  a.append(dd)


INF = 1e14
ans = INF
for iters in range(1,n+1):
  xx = list(itertools.combinations(range(n), iters))
  for u in xx:
    bad = False
    score = [0] * m
    money = 0
    for i in u:
      money += c[i]
      for j in range(m):
        score[j] += a[i][j]

    for j in range(m):
      if score[j] < x:
        bad = True
        break
    # print(u, money, score)
    if not bad:
      ans = min(money, ans)

  if ans < INF:
    break
    
if ans == INF:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = sorted(l)
l = np.array(l)
print(l)
ans = np.sum(l, 0)[0]
ans_s = np.sum(l, 0)
if np.any(ans_s[1:] < x):
    print(-1)
    exit()
count = 0
for i in range(1, m + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
            print(int(ans))
            exit()

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
 
n, m, x = map(int, input().split())
 
 
a_do = []
for i in range(n):
    a = list(map(int, input().split()))
    a_do.append(a)
 
 
nums = []
for i in range(n):
    nums.append(i)
 
temp = []
for i in range(1, n+1):
    for v in itertools.combinations(nums, i):
        rikaido = [0] * (m+1)
        for j in range(len(v)):
            for k in range(m+1):
                rikaido[k] += a_do[v[j]][k]
 
        temp.append(rikaido)
 
minimum = 10**20
for i in range(len(temp)):
    for j in range(1, m+1):
        if temp[i][j] < x:
            break
        minimum = min(minimum, temp[i][0])
 
if(minimum == 10**20):
    print(-1)
else:
    print(minimum)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
N, M, X = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(N)]
arr = np.array(arr)
sum_arr = np.sum(arr, axis=0)
if(all(sum_arr[1:]>=X)):
  minimum_sum=100000*12+1
  l = [i for i in range(N)]
  for m in range(1, M+1, 1):
    for v in itertools.combinations(l, m):
      temp_arr = arr[v,:]
      price_sum = temp_arr[:,0].sum()
      if all(np.sum(temp_arr, axis=0)[1:]>=X) and (minimum_sum>price_sum):
        minimum_sum = price_sum
  print(minimum_sum)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import itertools
n,m,x=list(map(int,input().split()))
ans=10**6
A=[list(map(int,input().split())) for i in range(n)]
B=sorted(A, key=lambda x: x[0])
#print(B)
D=[0]*(m+1)
for i, _ in enumerate(B, 1):
  for j in itertools.combinations(B,r=i):
    C=list(zip(*j))
#    print(C)
    for m in range(m+1):
      D[m]=sum(C[m])
#    print(D)
    E=[i for i in D[1:] if i>=x ]
    if len(E)==m:
      ans=min(ans,D[0])
print(ans) if ans!=10**6 else print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np  # NumPyモジュールをインポートする
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  # 全部intに変換

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  # 全部intに変換
    I[i] = val2

seq = [i for i in range(val[0])]  # 組み合わせを考える
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            # print("xxx=", j)
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

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

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
N, M, X = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(N)]
arr = np.array(arr)
sum_arr = np.sum(arr, axis=0)
if(all(sum_arr[1:]>=X)):
  minimum_sum=100000*12+1
  l = [i for i in range(N)]
  for m in range(2, M+1, 1):
    for v in itertools.combinations(l, m):
      temp_arr = arr[v,:]
      price_sum = temp_arr[:,0].sum()
      if all(np.sum(temp_arr, axis=0)[1:]>=X) and (minimum_sum>price_sum):
        minimum_sum = price_sum
  print(minimum_sum)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys
n,m,x= map(int, sys.stdin.readline().rstrip("\n").split())
lines = [ [int(s) for s in line.split()] for line in sys.stdin ]

books = {}
num = 0
for a in range(2):
    for b in range(2):
        for c in range(2):
            for d in range(2):
                for e in range(2):
                    for f in range(2):
                        for g in range(2):
                            for h in range(2):
                                for i in range(2):
                                    for j in range(2):
                                        for k in range(2):
                                            for l in range(2):
                                                books[num] = [a,b,c,d,e,f,g,h,i,j,k,l]
                                                num += 1
price = -1
skill = {}
for i in range(2**12-1):
    price_ = 0
    for j in range (m):
        skill[j] = 0
    for j in range(n):
        if books[i][j] == 1:
            price_  += lines[j][0]
            for k in range(m):
                skill[k] = skill[k] + lines[j][k+1]
        for k in range(m):
            if skill[k] < x:
                break
        else:
            if price == -1:
                price = price_
            else:
                price = min(price, price_)
print(price)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

def function(CA, n, total, skill, C, X_l):
  CAn = CA[n]
  An = CAn[1:]
  skill = np.array(skill) + np.array(An)
  skill = skill.tolist()
  total += CAn[0]
  if skill >= X_l:
    C.append(total)
  return total, skill, C

C = []
X_l = [X]*M
for a in range(N):
  total = 0
  skill = [0]*M
  total_a, skill_a, C = function(CA, a, total, skill, C, X_l)
  if a == N-1:
    break
  for b in range(a+1, N):
    total_b, skill_b, C = function(CA, b, total_a, skill_a, C, X_l)
    if b == N-1:
      break
    for c in range(b+1, N):
      total_c, skill_c, C = function(CA, c, total_b, skill_b, C, X_l)
      if c == N-1:
        break
      for d in range(c+1, N):
        total_d, skill_d, C = function(CA, d, total_c, skill_c, C, X_l)
        if d == N-1:
          break
        for e in range(d+1, N):
          total_e, skill_e, C = function(CA, e, total_d, skill_d, C, X_l)
          if e == N-1:
            break
          for f in range(e+1, N):
            total_f, skill_f, C = function(CA, f, total_e, skill_e, C, X_l)
            if f == N-1:
              break
            for g in range(f+1, N):
              total_g, skill_g, C = function(CA, g, total_f, skill_f, C, X_l)
              if g == N-1:
                break
              for h in range(g+1, N):
                total_h, skill_h, C = function(CA, h, total_g, skill_g, C, X_l)
                if h == N-1:
                  break
                for i in range(h+1, N):
                  total_i, skill_i, C = function(CA, i, total_h, skill_h, C, X_l)
                  if i == N-1:
                    break
                  for j in range(i+1, N):
                    total_j, skill_j, C = function(CA, j, total_i, skill_i, C, X_l)
                    if j == N-1:
                      break
                    for k in range(j+1, N):
                      total_k, skill_k, C = function(CA, k, total_j, skill_j, C, X_l)
                      if k == N-1:
                        break
                      for l in range(k+1, N):
                        total_l, skill_l, C = function(CA, l, total_k, skill_k, C, X_l)

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

Submission status: Wrong Answer

Solution code:
DEBUG = False

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

if DEBUG:
    print(A)
    print(C)

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

if ans_money == max_money:
    print(-1)
else:
    print(ans_money)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
N,M,X = map(int,input().split( ))
CA = np.array([list(map(int,input().split( ))) for _ in range(N)])
A = CA[:,1:]
C = CA[:,0]
ans = -1
for i in range(N):
    money = []
    xs = []
    for j in itertools.permutations(np.arange(N),i+1):
        x = np.min(np.sum(A[list(j)],0))
        xs.append(x)
        if x >= X:
            money.append(np.sum(C[list(j)]))
    if np.max(xs) >= X:
        ans = np.min(money)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m, x = [int(k) for k in input().split()]
c = np.zeros(n, dtype=int)
a = np.zeros((n, m), dtype=int)
rikai_a = np.zeros(m, dtype=int)
bool_c = np.full(n, False)
for l in range(n):
    c[l], *a[l] = [int(k) for k in input().split()]
money = 0
finish = False
ave = np.zeros(n)
while True:
    count = 0
    for l in range(n):
        if bool_c[l]:
            count += 1
        ave[l] = sum([min(x - rikai_a[b], a[l][b]) if rikai_a[b] + a[l][b] > x else a[l][b] for b in range(m)]) / c[l]
    if count == n:
        break
    i = np.argsort(ave)[:: -1][0]
    if not bool_c[i]:
        rikai_a[:] += a[i]
        money += c[i]
        a[i] = 0
        c[i] = 1
        bool_c[i] = True
    for b in range(m):
        if rikai_a[b] < x:
            break
    else:
        finish = True
        break
    continue
if finish:
    print(money)
else:
    print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
INF = float("inf")
import sys,collections

N,M,X = map(int,sys.stdin.readline().split())

C = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param

ALL = [0]*(M+1)
for a in C:
    for i in range(M+1):
        ALL[i] += a[i]
#print(ALL,X)
if any(e < X for e in ALL[1:]):
    print(-1)
    exit()

dp = [[INF]*(M+1) for _ in range(N+1)]
dp[0] = ALL
for i in range(N+1):
    dp[i] = dp[max(0,i-1)]
    for j in range(i):
        #print(i,j,dp[j],C[i-1],X)
        # print(i,j,X,[(e2-e1) for e1,e2 in zip(C[j][1:],dp[j][1:])],
        #              all((e2-e1)>=X for e1,e2 in zip(C[j][1:],dp[j][1:])))
        if X < dp[j][0]-C[i-1][0] and dp[j][0]-C[i-1][0] < dp[i][0] and all((e2-e1)>=X for e1,e2 in zip(C[i-1][1:],dp[j][1:])):
            dp[i] = [e3-e4 for e3,e4 in zip(dp[j],C[i-1])]
#print(dp)
print(dp[-1][0])

Submission status: Wrong Answer

Solution code:
import sys 
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
def dp(start,algo,cost):
	if start>=n:
		return
	global ans
	if all([True if i>=x else False for i in algo ]):
		ans = min(ans, cost)

	for i in range(start,n):
		temp = list(algo)
		for j in range(1,m+1):
			temp[j-1] += arr[i][j]
		for k in range(i+1,n):
			dp(k, temp, cost+arr[i][0])

for tt in range(1):
	n,m,x = map(int,input().split())
	arr = []
	cost = [0]*m
	ans = float('inf')
	for i in range(n):
		l = list(map(int,input().split()))
		arr.append(l)
	dp(0,cost,0)
	if ans != float('inf'):
		print(ans)
	else:
		print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

def function(CA, n, total, skill, C, X_l):
  CAn = CA[n]
  An = CAn[1:]
  skill = np.array(skill) + np.array(An)
  skill = skill.tolist()
  total += CAn[0]
  if skill >= X_l:
    C.append(total)
  return total, skill, C

C = []
X_l = [X]*M
for a in range(N):
  total = 0
  skill = [0]*M
  total_a, skill_a, C = function(CA, a, total, skill, C, X_l)
  if a == N-1:
    break
  for b in range(a+1, N):
    total_b, skill_b, C = function(CA, b, total_a, skill_a, C, X_l)
    if b == N-1:
      break
    for c in range(b+1, N):
      total_c, skill_c, C = function(CA, c, total_b, skill_b, C, X_l)
      if c == N-1:
        break
      for d in range(c+1, N):
        total_d, skill_d, C = function(CA, d, total_c, skill_c, C, X_l)
        if d == N-1:
          break
        for e in range(d+1, N):
          total_e, skill_e, C = function(CA, e, total_d, skill_d, C, X_l)
          if e == N-1:
            break
          for f in range(e+1, N):
            total_f, skill_f, C = function(CA, f, total_e, skill_e, C, X_l)
            if f == N-1:
              break
            for g in range(f+1, N):
              total_g, skill_g, C = function(CA, g, total_f, skill_f, C, X_l)
              if g == N-1:
                break
              for h in range(g+1, N):
                total_h, skill_h, C = function(CA, h, total_g, skill_g, C, X_l)
                if h == N-1:
                  break
                for i in range(h+1, N):
                  total_i, skill_i, C = function(CA, i, total_h, skill_h, C, X_l)
                  if i == N-1:
                    break
                  for j in range(i+1, N):
                    total_j, skill_j, C = function(CA, j, total_i, skill_i, C, X_l)
                    if j == N-1:
                      break
                    for k in range(j+1, N):
                      total_k, skill_k, C = function(CA, k, total_j, skill_j, C, X_l)
                      if k == N-1:
                        break
                      for l in range(k+1, N):
                        total_l, skill_l, C = function(CA, l, total_k, skill_k, C, X_l)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

def can_reach_the_goal(u, x):
    return min(u) >= x

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

c = []
a = []
u = [0]*m
u_sum = [0]*n
for i in range(n):
    ca = [int(row) for row in input().split()]
    c.append(ca[0])
    a.append(ca[1:])
    u_sum[i] += sum(a[i])
    for j in range(m):
        u[j] += a[i][j]

if not can_reach_the_goal(u, x):
    print(-1)
    sys.exit()

idx_c = list(np.argsort(-1 * np.array(c)))
c_sum = sum(c)
for i in idx_c:
    u_tmp = [u[j] - a[i][j] for j in range(m)]
    if can_reach_the_goal(u_tmp, x):
        c_sum -= c[i]
        u = u_tmp

print(c_sum)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = sorted(l)
l = np.array(l)
ans = np.sum(l, 0)[0]
ans_s = np.sum(l, 0)
if np.any(ans_s[1:] < x):
    print(-1)
    exit()
count = 0
for i in range(1, n + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
            print(int(ans))
            exit()

Submission status: Wrong Answer

Solution code:
N, M, X = map(int,input().split())
a=[]
b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
c=[]
for i in range(N):
    a.append(input().split())
    c.append(0)

check=0
ans=-1
for i in range(1,(2**N)-1):
    b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    for j in range(N):
        check=0
        if 0x01 & (i >> j):
            for n in range(M+1):
                b[n] = b[n] + int(a[j][n])
        #print(b)
        for k in range(1,M):
            if b[k] < X:
                #print(k)
                check=1
                break
        if check==0:
            #print(ans)
            if ans == -1 or ans > b[0]:
                ans = b[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np  # NumPyモジュールをインポートする
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  # 全部intに変換

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  # 全部intに変換
    I[i] = val2

seq = [i for i in range(val[0])]  # 組み合わせを考える
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    # print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            # print("xxx=", j)
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

#標準出力からの読み込み
input_1 = input()
n = int(input_1.split(" ")[0])
m = int(input_1.split(" ")[1])
x = int(input_1.split(" ")[2])

knowledge = []
for i in range(n):
    input_array = [int(s) for s in input().split(" ")]
    knowledge.append(input_array)

#判定ロジック
#そのそも、目標を達成できない場合は終わり
output = 0
for i in range(m):
    sum = 0
    for j in range(n):
        sum += knowledge[j][i]
    if sum < x:
        output = '-1'

if output == '-1':
    print(output)
    exit()

tmp_sum = 0
for i in range(n):
    tmp_sum += knowledge[i][0]

cost = tmp_sum
pattern = '{:0' + str(n) + 'b}'
#高々12個の最適化なので総当たりで調べる
for i in range(2**n):
    tmp_cost = 0
    skill_array = [0 for s in range(m)]
    for j in range(n):
        if pattern.format(i)[j] == "1":
            tmp_cost += knowledge[j][0]
            skill_array = list(map(lambda x,y: x + y, skill_array, knowledge[j][1:]))

    for k in range(m):
        if skill_array[k] < x:
            break
    else:
        if cost > tmp_cost:
            cost = tmp_cost

output = cost
print(output)