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.

Submission attempts (in order):
n,m,x=map(int,input().split())
nedan=[]
grade=[]
ans=-1
for i in range(n):
  s=list(map(int,input().split())) 
  nedan.append(s.pop(0))
  grade.append(s)

#print(grade)

for i in range(2**n):
  shopping=[]
  total_grade=[]
  for j in range(n):
    if (( i >> j ) & 1):
      shopping.append(nedan[j])
      print(nedan[j])
      total_grade.append(grade[j])
      print(grade[j])

  t=sum(shopping)
  print(t)
  print(shopping)
  print(total_grade)
  sum_grade=[]
  for j in range(m):
    s=0
    for k in range(len(total_grade)):
        s+=total_grade[k][j]
    sum_grade.append(s)

  if sum_grade >=[x]*len(total_grade):
    ans=t
    break
print(t)
if ans==-1:
  print(-1)

else:
  print(ans)

import sys
import numpy as np
sys.setrecursionlimit(10**8)

def dfs(i,a,value):
  global ans
  if i==n:
    if all(a[i]>=x for i in range(m)):
      ans=min(ans,value)

    else:
      ans=-1

  else:
    dfs(i+1,a,value)
    dfs(i+1,a+np.array(pc[i][1:]),value+pc[i][0])


ans=float('inf')
n,m,x=map(int,input().split())
pc=[]
for i in range(n):
  s=list(map(int,input().split()))
  pc.append(s)

dfs(0,np.array([0]*(m)),0)
print(ans)

n,m,x=map(int,input().split())
nedan=[]
grade=[]
inf=12*10**6
for i in range(n):
  s=list(map(int,input().split())) 
  nedan.append(s.pop(0))
  grade.append(s)

#print(grade)

for i in range(2**n):
  shopping=[]
  total_grade=[]
  for j in range(n):
    if (( i >> j ) & 1):
      shopping.append(nedan[j])
      total_grade.append(grade[j])

  t=sum(shopping)
  #print(t)
  #print(shopping)
  #print(total_grade)
  sum_grade=[]
  for j in range(m):
    s=0
    for k in range(len(total_grade)):
        s+=total_grade[k][j]
    sum_grade.append(s)
    print(sum_grade)

  ans_t=[]
  if all(j>=x for j in sum_grade):
    ans_t.append(t)

print(ans_t)   
ans=min(ans_t)

if min(ans,inf)==ans:
  print(ans)

else:
  print(-1)

def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

import sys
import numpy as np

sys.setrecursionlimit(10**8)
n,m,x=mi()
list_ans=[]
for i in range(n):
  c_=lmi()
  list_ans.append(c_)

ans=float('inf')

def dfs(i,suma,count):
  global ans
  if i==n:
    
    if np.all(count>=x):
      ans=min(ans,suma)
      return ans

  else:
    dfs(i+1,suma,count)
    dfs(i+1,suma+list_ans[i][0],count+np.array(list_ans[i][1:]))

dfs(0,0,np.array([0]*m))
if ans==float('inf'):
  print(-1)
  exit()
  
else:
  print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted