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

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

C = np.array([list(map(int, input().split())) for _ in range(N)])
# print(C)
sum_C = np.sum(C,axis=0)
# print(sum_C)

for num in sum_C:
    if num < X:
        print(-1)
        exit()

cost = float("inf")

for ii in [0, 1]:
    for i in range(M+1):
        cc = sorted(C, key=lambda x:x[0], reverse=True)
        ccc = np.array(sorted(cc, key=lambda x:x[i], reverse=ii))
        # print("ccc", ccc)
        sum_Ccopy = np.zeros(M+1)
        for j in range(N):
            sum_Ccopy += ccc[j]

            # print(np.all(sum_Ccopy[1:] >= X))
            # print(sum_Ccopy[0])
            if np.all(sum_Ccopy[1:] >= X):
                cost = min(cost, sum_Ccopy[0])
                # print(sum_Ccopy[0])
                print("sum_Ccopy", sum_Ccopy)
            # print(cost)
    
print(int(cost))




import numpy as np

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

C = np.array([list(map(int, input().split())) for _ in range(N)])
# print(C)
sum_C = np.sum(C,axis=0)
# print(sum_C)

for num in sum_C:
    if num < X:
        print(-1)
        exit()

cost = float("inf")

for ii in [0, 1]:
    for i in range(M+1):
        cc = sorted(C, key=lambda x:x[0], reverse=False)
        ccc = np.array(sorted(cc, key=lambda x:x[i], reverse=ii))
        # print("ccc", ccc)
        sum_Ccopy = np.zeros(M+1)
        for j in range(N):
            sum_Ccopy += ccc[j]

            # print(np.all(sum_Ccopy[1:] >= X))
            # print(sum_Ccopy[0])
            if np.all(sum_Ccopy[1:] >= X):
                cost = min(cost, sum_Ccopy[0])
                # print(sum_Ccopy[0])
                print("sum_Ccopy", sum_Ccopy)
            # print(cost)
    
print(int(cost))




import numpy as np

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

C = np.array([list(map(int, input().split())) for _ in range(N)])
# print(C)
sum_C = np.sum(C,axis=0)
# print(sum_C)

for num in sum_C:
    if num < X:
        print(-1)
        exit()

cost = float("inf")
for ij in [0, 1]:
    for ii in [0, 1]:
        for i in range(M+1):
            cc = sorted(C, key=lambda x:x[0], reverse=ij)
            ccc = np.array(sorted(cc, key=lambda x:x[i], reverse=ii))
            # print("ccc", ccc)
            sum_Ccopy = np.zeros(M+1)
            for j in range(N):
                sum_Ccopy += ccc[j]

                # print(np.all(sum_Ccopy[1:] >= X))
                # print(sum_Ccopy[0])
                if np.all(sum_Ccopy[1:] >= X):
                    cost = min(cost, sum_Ccopy[0])
                    # print(sum_Ccopy[0])
                    print("sum_Ccopy", sum_Ccopy)
                # print(cost)
    
print(int(cost))




import numpy as np

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

C = np.array([list(map(int, input().split())) for _ in range(N)])

cost = float("inf")

for i in range(2**N):
    buy = np.zeros(M+1)
    for j in range(N):
        if ((i >> j)&1):
            buy += C[j]
        if np.all(buy[1:] >= X):
            cost = min(cost, buy[0])

if cost == float("inf"):
    print(-1)
else:
    print(int(cost))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted