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):
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 = []

suit =[]
for i in range(M+1):
    a.append(0)
    

#    suit.append([])

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):
            #print("x+y=",x+y)
            #print("i=",i)
            a[i] += L[x+y-1][i]
            
        print("a",a)
        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):
    print("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)

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:
        print(a)
        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)

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:
        print(a)
        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(suit)
print(price)

def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y

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

L = []
a = []

for i in range(N):
    text = input().split()
    L.append(intlist(text))
    
for i in range(N):
    for j in range(N-1):
        if L[j] > L[j+1]:
            a = L[j]
            L[j] = L[j+1]
            L[j+1] = a

score = []
count = 0
money = -1
money_count = 0


for i in range(M):            
    score.append(0)
            
for i in range(N):
    money_count = money_count + L[i][0]
    for j in range(M):
        score[j] = score[j] + L[i][j+1]
    if min(score) >= X:
        money = money_count
        break


score2 = score

if money != -1:

    for i in range(N):
        for j in range(M):
            score2[j] -= L[len(L)-1-i][j+1]
            print(score2)
        if min(score2) >= X:
            money = money - L[len(L)-1-i][0]
        else:
            for k in range(M):
                score2[k] += L[len(L)-1-i][k+1]
       
        
          
print(money)

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))
    
for i in range(2**N):
    c = a.copy()
    
    for j in range(N):
        if (i >> j) & 1:
            for k in range(M+1):
                c[k] = c[k] + L[j][k]
    suit.append(c.copy())
                
suit2 = []

for i in range(len(suit)):
    if min(suit[i][1:len(suit)]) >= X:
        suit2.append(suit[i])
        


if suit2 != []:
    if len(suit2) >= 2:
    
        cheaper = suit2[0][0]
        for i in range(len(suit2)):
            if cheaper > suit2[i][0]:
                cheaper = suit2[i][0]
        price = cheaper
    elif len(suit2) == 1:
        price = suit2[0][0]
        
print(price)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted