Problem:


Score : 400 points

Problem Statement

Dolphin is planning to generate a small amount of a certain chemical substance C.

In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b.

He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy.

The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock.

The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan).

Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C.

Find the minimum amount of money required to generate the substance C.

If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact.  

Constraints

1≦N≦40 

1≦a_i,b_i≦10 

1≦c_i≦100 

1≦M_a,M_b≦10 

gcd(M_a,M_b)=1

a_i, b_i, c_i, M_a and M_b are integers.

Input

The input is given from Standard Input in the following format:

N M_a M_b  
a_1 b_1 c_1  
a_2 b_2 c_2
:  
a_N b_N c_N  

Output

Print the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C, print -1 instead.

Sample Input 1

3 1 1
1 2 1
2 1 2
3 3 10

Sample Output 1

3

The amount of money spent will be minimized by purchasing the packages of chemicals 1 and 2.

In this case, the mixture of the purchased chemicals will contain 3 grams of the substance A and 3 grams of the substance B, which are in the desired ratio: 3:3=1:1.

The total price of these packages is 3 yen.  

Sample Input 2

1 1 10
10 10 10

Sample Output 2

-1

The ratio 1:10 of the two substances A and B cannot be satisfied by purchasing any combination of the packages. Thus, the output should be -1.



Sample input:
3 1 1
1 2 1
2 1 2
3 3 10


Sample output:
3

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
X = [1<<20] * 4040
for _ in range(N):
    a, b, c = map(int, input().split())
    t = A*b-B*a
    X = [min(X[i], (0 if i == t else X[(i-t)%4040]) + c) for i in range(4040)]
print(-1 if X[0] > 1<<18 else X[0])

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
X = [1<<100] * 8080
for _ in range(N):
    a, b, c = map(int, input().split())
    t = A*b-B*a
    X = [min(X[i], (0 if i == t else X[(i-t)%N]) + c) for i in range(8080)]

print(-1 if X[0] > 1<<80 else X[0])

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
X = [1<<100] * 8080
for _ in range(N):
    a, b, c = map(int, input().split())
    t = A*b-B*a
    X[t] = min(X[t], c)
    X = [min(X[i], X[(i-t)%N] + c) for i in range(8080)]

print(-1 if X[0] > 1<<80 else X[0])

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
X = [1<<20] * 4040
for _ in range(N):
    a, b, c = map(int, input().split())
    t = A*b-B*a
    X[t] = min(X[t], c)
    X = [min(X[i], X[(i-t)%N] + c) for i in range(4040)]

print(-1 if X[0] > 1<<19 else X[0])

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
X = [1<<100] * 8080
for _ in range(N):
    a, b, c = map(int, input().split())
    t = A*b-B*a
    X[t] = min(X[t], c)
    for i in range(-4000, 4001):
        X[i] = min(X[i], X[i-t] + c)

print(-1 if X[0] > 1<<80 else X[0])

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N,M_a,M_b=list(map(int,input().split()))
    A,B,C=[],[],[]
    for i in range(N):
        a,b,c=list(map(int,input().split()))
        A.append(a)
        B.append(b)
        C.append(c)

    dp=[[[1e10 for i in range(sum(B)+max(B)+1)] for j in range(sum(A)+max(A)+1)] for k in range(N+1)]
    dp[0][0][0]=0

    for i in range(N):
        for c_a in range(sum(A)+1):
            for c_b in range(sum(B)+1):
                if dp[i][c_a][c_b]==1e10:
                    continue
                dp[i+1][c_a][c_b]=min(dp[i+1][c_a][c_b],dp[i][c_a][c_b])
                dp[i+1][c_a+A[i]][c_b+B[i]]=min(dp[i+1][c_a+A[i]][c_b+B[i]],dp[i][c_a][c_b]+C[i])
    ans_list=[1e10]
    for c_a in range(1,sum(A)+1):
        for c_b in range(1,sum(B)+1):
            if c_a*M_b==c_b*M_a:
                ans_list.append(dp[N-1][c_a][c_b])
    ans=min(ans_list)
    if  ans==1e10:
        print(-1)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N,M_a,M_b=list(map(int,input().split()))
    A,B,C=[],[],[]
    for i in range(N):
        a,b,c=list(map(int,input().split()))
        A.append(a)
        B.append(b)
        C.append(c)

    dp=[[[1e10 for i in range(max(B)*(N+1))] for j in range(max(A)*(N+1))] for k in range(N+1)]
    dp[0][0][0]=0

    for i in range(N):
        for c_a in range(max(A)*N):
            for c_b in range(max(B)*N):
                if dp[i][c_a][c_b]==1e10:
                    continue
                dp[i+1][c_a][c_b]=min(dp[i+1][c_a][c_b],dp[i][c_a][c_b])
                dp[i+1][c_a+A[i]][c_b+B[i]]=min(dp[i+1][c_a+A[i]][c_b+B[i]],dp[i][c_a][c_b]+C[i])
    ans_list=[1e10]
    for c_a in A:
        for c_b in B:
            if c_a*M_b==c_b*M_a:
                ans_list.append(dp[N][c_a][c_b])

    ans=min(ans_list)

    if  ans==1e10:
        print(-1)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:


N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    

INF = float("inf")
sA = sum(a)
sB = sum(b)
# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(401)] for _ in range(401)]
dp[0][0] = 0

for i in range(N):
    for j in range(401):
        for k in range(401):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF

x = Ma
y = Mb
while x <= sA and y <= sB :

    ans = min(ans, dp[x][y])
    x += Ma
    y += Mb


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

Submission status: Wrong Answer

Solution code:


N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    

INF = float("inf")
sA = sum(a)
sB = sum(b)
# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(sB+1)] for _ in range(sA+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(sA+1):
        for k in range(sB+1):
            if a[i] <= j and  b[i] <= k and dp[j - a[i]][k - b[i]] != INF:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF

x = Ma
y = Mb
while x <= sA and y <= sB :

    ans = min(ans, dp[x][y])
    x += Ma
    y += Mb


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

Submission status: Wrong Answer

Solution code:


N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    

INF = float("inf")
sA = sum(a)
sB = sum(b)
# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(sB+1)] for _ in range(sA+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(sA+1):
        for k in range(sB+1):
            if a[i] <= j and  b[i] <= k and dp[j - a[i]][k - b[i]] != INF:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF

i = 1
while Ma*i <= sA and Mb*i <= sB :

    ans = min(ans, dp[Ma*i][Mb*i])
    i += 1


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

Submission status: Wrong Answer

Solution code:


N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    

INF = float("inf")
sA = sum(a)
sB = sum(b)
# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(sB+1)] for _ in range(sA+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(sA+1):
        for k in range(sB+1):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF

i = 1
while Ma*i <= sA and Mb*i <= sB :

    ans = min(ans, dp[Ma*i][Mb*i])
    i += 1


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

Submission status: Wrong Answer

Solution code:


N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    

INF = float("inf")

# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(401)] for _ in range(401)]
dp[0][0] = 0

for i in range(N):
    for j in range(401):
        for k in range(401):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF

i = 1
while i <= 40:
    ans = min(ans, dp[Ma*i][Mb*i])
    i += 1


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

Submission status: Wrong Answer

Solution code:


N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    

INF = float("inf")

# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(401)] for _ in range(401)]
dp[0][0] = 0

for i in range(N):
    for j in range(401):
        for k in range(401):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF


for i in range(1,41):
    ans = min(ans, dp[Ma*i][Mb*i])


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

Submission status: Wrong Answer

Solution code:

N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    
maxA = max(a)
maxB = max(b)


INF = float("inf")

# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(401)] for _ in range(401)]
dp[0][0] = 0

for i in range(N):
    for j in range(401):
        for k in range(401):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF
i = 1

for i in range(1,41):
    ans = min(ans, dp[Ma*i][Mb*i])


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

Submission status: Wrong Answer

Solution code:

N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    
maxA = max(a)
maxB = max(b)


INF = float("inf")

# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(401)] for _ in range(401)]

dp[0][0] = 0

for i in range(N):
    for j in range(401):
        for k in range(401):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])


ans = INF
i = 1
tmp1 = sum(a)+1
tmp2 = sum(b)+1
while Ma*i <= tmp1 and Mb*i <= tmp2:
    ans = min(ans, dp[Ma*i][Mb*i])
    i += 1

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

Submission status: Wrong Answer

Solution code:

N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    
maxA = max(a)
maxB = max(b)


INF = float("inf")

# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(411)] for _ in range(411)]

dp[0][0] = 0

for i in range(N):
    for j in range(401):
        for k in range(401):
            #if a[i] <= j and  b[i] <= k:
            dp[j + a[i]][k + b[i]] = min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i])

ans = INF
i = 1
tmp1 = sum(a)+1
tmp2 = sum(b)+1
while Ma*i <= tmp1 and Mb*i <= tmp2:
    ans = min(ans, dp[Ma*i][Mb*i])
    i += 1

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

Submission status: Wrong Answer

Solution code:

N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    
cum_a = [0] * N
cum_b = [0] * N
cum_a[0] = a[0]
cum_b[0] = b[0]
for i in range(1,N):
    cum_a[i] = cum_a[i-1] + a[i]
    cum_b[i] = cum_b[i-1] + b[i]


INF = float("inf")

# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(cum_b[-1]+1)] for _ in range(cum_a[-1]+1)]

dp[0][0] = 0

for i in range(N):
    for j in range(cum_a[-1]+1):
        for k in range(cum_b[-1]+1):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])

ans = INF
i = 1
while Ma*i <= cum_a[-1] and Mb*i <= cum_b[-1]:
    ans = min(ans, dp[Ma*i][Mb*i])
    i += 1

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

Submission status: Wrong Answer

Solution code:


N, Ma, Mb = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    
cum_a = [0] * N
cum_b = [0] * N
cum_a[0] = a[0]
cum_b[0] = b[0]
for i in range(1,N):
    cum_a[i] = cum_a[i-1] + a[i]
    cum_b[i] = cum_b[i-1] + b[i]


INF = float("inf")

# 薬A,Bの合計がi,jになるのに必要な最小金額
dp = [[INF for _ in range(cum_b[-1]+1)] for _ in range(cum_a[-1]+1)]

dp[0][0] = 0

for i in range(N):
    for j in range(cum_a[i]+1):
        for k in range(cum_b[i]+1):
            if a[i] <= j and  b[i] <= k:
                dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i])

ans = INF
i = 1
while Ma*i <= cum_a[-1] and Mb*i <= cum_b[-1]:
    ans = min(ans, dp[Ma*i][Mb*i])
    i += 1

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

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(n)]
suma = sum([abc[i][0] for i in range(n)])+1
sumb = sum([abc[i][1] for i in range(n)])+1
dp = [[[5000 for j in range(sumb)]for i in range(suma)]for k in range(n+1)]
for i in range(n+1):
    dp[i][0][0] = 0
for k in range(n):
    for i in range(suma):
        for j in range(sumb):
            if i>=abc[k][0] and j>=abc[k][1]:
                dp[k+1][i][j] = min(dp[k][i][j],dp[k][i-abc[k][0]][j-abc[k][1]]+abc[k][2])
            else:
                dp[k+1][i][j]=dp[k][i][j]

flag = 0
for i in range(1,500):
    if ma*i >=suma or mb*i >= sumb:
        break
    if dp[n][ma*i][mb*i] != 5000:
        res = dp[n][ma*i][mb*i]
        flag = 1
        break
if flag:
    print(res)
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n, ma, mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(n)]

m = n * 10 + 1

dp1 = [[float('inf')] * m for i in range(n + 1)]
for i in range(n + 1):
    dp1[i][0] = 0
for i in range(n):
    for j in range(m):
        dp1[i+1][j] = min(dp1[i+1][j], dp1[i][j])
        # i個目を買う
        jj = j + abc[i][0]
        if jj <= m - 1:
            dp1[i+1][jj] = min(dp1[i+1][jj], dp1[i][j] + abc[i][2])

dp2 = [[float('inf')] * m for i in range(n + 1)]
for i in range(n + 1):
    dp2[i][0] = 0
for i in range(n):
    for j in range(m):
        dp2[i+1][j] = min(dp2[i+1][j], dp2[i][j])
        # i個目を買う
        jj = j + abc[i][1]
        if jj <= m - 1:
            dp2[i+1][jj] = min(dp2[i+1][jj], dp2[i][j] + abc[i][2])

from fractions import gcd
ans = float('inf')
for i in range(1, m):
    for j in range(1, m):
        d1 = dp1[-1][i]
        d2 = dp2[-1][j]
        g = gcd(i, j)
        if i // g == ma and j // g == mb:
            ans = min(ans, d1 + d2)

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import product
def resolve():
    n,ma,mb=map(int,input().split())
    ABC=[tuple(map(int,input().split())) for _ in range(n)]
    M=400

    dp=[[INF]*(M+1) for _ in range(M+1)]
    dp[0][0]=0

    for a,b,c in ABC:
        for x,y in product(range(M+1),repeat=2):
            if(x+a<=M and y+b<=M):
                dp[x+a][y+b]=min(dp[x+a][y+b],dp[x][y]+c)

    ans=INF
    for x,y in product(range(1,M+1),repeat=2):
        if(x*mb==y*ma): ans=min(ans,dp[x][y])
    if(ans==INF): ans=-1
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
def main():
    N, Ma, Mb = map(int, input().split())
    a = [0] * N
    b = [0] * N
    c = [0] * N
    for i in range(N):
        a[i], b[i], c[i] = map(int, input().split())

    dp = [[[float('inf')] * (405) for _ in range(405)] for _ in range(N + 5)]    
    dp[0][0][0] = 0

    for i in range(N):
        for j in range(401):
            for k in range(401):
                if dp[i][j][k] == float('inf'):
                    continue
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i])

    ans = float('inf')
    for i in range(1,401):
        for j in range(1,401):
            if Mb * j == Ma * i:
                ans = min(ans, dp[N][i][j])

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product

MAX = 10**4
N, Ma, Mb = map(int, input().split())
chems = [tuple(map(int, input().split())) for _ in range(N)]
chems = sorted(chems, key=lambda x: x[2])
rng = range(11)
dp = [[[None for _ in rng] for _ in rng] for _ in range(N+1)]
dp[0][0][0] = MAX
for i, (a, b, c) in enumerate(chems):
    for j, k in product(rng, repeat=2):
        if j < a or k < b:
            dp[i+1][j][k] = dp[i][j][k]
        else:
            if dp[i][j-a][k-b] == MAX:
                dp[i+1][j][k] = min(c, dp[i][j][k]) if dp[i][j][k] is not None else c
            elif dp[i][j-a][k-b] is not None:
                dp[i+1][j][k] = min(dp[i][j-a][k-b] + c, dp[i][j][k]) if dp[i][j][k] is not None else dp[i][j-a][k-b] + c
            else:
                dp[i+1][j][k] = dp[i][j][k]
ans = MAX
for j, k in product(rng, repeat=2):
    if j == 0 or k == 0: continue
    if j * Mb == k * Ma and dp[N][j][k] is not None:
        ans = min(ans, dp[N][j][k])
print(-1 if ans == MAX else ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

MAX = 10**4
N, Ma, Mb = map(int, input().split())
chems = [tuple(map(int, input().split())) for _ in range(N)]
chems = sorted(chems, key=lambda x: x[2])
rng = range(401)
dp = [[[MAX for _ in rng] for _ in rng] for _ in range(N)]
dp[0][chems[0][0]][chems[0][1]] = chems[0][2]
for i, (a, b, c) in enumerate(chems[1:]):
    for j, k in product(rng, repeat=2):
        if j < a or k < b or dp[i][j-a][k-b] == MAX:
            dp[i+1][j][k] = dp[i][j][k]
        else:
            dp[i+1][j][k] = min(dp[i][j-a][k-b] + c, dp[i][j][k])
ans = MAX
for j, k in product(rng, repeat=2):
    if j * Mb == k * Ma:
        ans = min(ans, dp[N-1][j][k])
print(-1 if ans == MAX else ans)

Submission status: Wrong Answer

Solution code:
n, ma, mb = map(int, input().split())
a, b, c = [0]*n, [0]*n, [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
   
dp = [[float('inf')] * (sum(b)+1) for _ in range(sum(a)+1)]
dp[0][0] = 0
step = set([(0, 0)])

for i in range(n):
    ai, bi = a[i], b[i]

    s = step.copy()
    for si in s:
        if dp[si[0]+ai][si[1]+bi] > dp[si[0]][si[1]] + c[i]:
            dp[si[0]+ai][si[1]+bi] = dp[si[0]][si[1]] + c[i]
            step.add((si[0]+ai, si[1]+bi))

ans = float('inf')
for i in range(1, min(sum(a)//ma, sum(b)//mb)+1):
    ans = min(ans, dp[ma*i][mb*i])
    
if ans == float('inf'): print(-1)
else : print(ans)

Submission status: Wrong Answer

Solution code:
n, ma, mb = map(int, input().split())
a, b, c = [0]*n, [0]*n, [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
   
dp = [[float('inf')] * (sum(b)+1) for _ in range(sum(a)+1)]
dp[0][0] = 0
step = [(0, 0)]

for i in range(n):
    ai, bi = a[i], b[i]

    s = step.copy()
    for si in s:
        if dp[si[0]+ai][si[1]+bi] > dp[si[0]][si[1]] + c[i]:
            dp[si[0]+ai][si[1]+bi] = dp[si[0]][si[1]] + c[i]
            step.append((si[0]+ai, si[1]+bi))

ans = float('inf')
for i in range(1, min(sum(a)//ma, sum(b)//mb)+1):
    ans = min(ans, dp[ma*i][mb*i])
    
if ans == float('inf'): print(-1)
else : print(ans)

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(n)]
l=10*n
inf=float("inf")
data=[[inf]*(l+1) for i in range(l+1)]
data[0][0]=0
for u in abc:
    a,b,c=u
    h=[[inf]*(l+1) for i in range(l+1)]
    h[0][0]=0
    for i in range(l-a+1):
        for j in range(l-b+1):
            if data[i][j]!=inf:
                h[i+a][j+b]=min(data[i+a][j+b],data[i][j]+c)
    data=h
k=1
ans=inf
while ma*k<=l and mb*k<=l:
    if data[ma*k][mb*k]!=inf:
        ans=min(ans,data[ma*k][mb*k])
    k+=1
if ans!=inf:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(n)]
l=10*n
inf=float("inf")
data=[[inf]*(l+1) for i in range(l+1)]
data[0][0]=0
for u in abc:
    a,b,c=u
    for i in range(l-a+1):
        for j in range(l-b+1):
            if data[i][j]!=inf:
                data[i+a][j+b]=min(data[i+a][j+b],data[i][j]+c)

k=1
ans=inf
while ma*k<=l and mb*k<=l:
    if data[ma*k][mb*k]!=inf:
        ans=min(ans,data[ma*k][mb*k])
    k+=1
if ans!=inf:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(n)]
l=10*n
inf=float("inf")
data=[[inf]*(l+1) for i in range(l+1)]
data[0][0]=0
for u in abc:
    a,b,c=u
    for i in range(l-a):
        for j in range(l-b):
            if data[i][j]!=inf:
                data[i+a][j+b]=min(data[i+a][j+b],data[i][j]+c)

k=1
ans=inf
while ma*k<=l and mb*k<=l:
    if data[ma*k][mb*k]!=inf:
        ans=min(ans,data[ma*k][mb*k])
    k+=1
if ans!=inf:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(n)]
l=10*n
inf=float("inf")
data=[[inf]*(l+1) for i in range(l+1)]
data[0][0]=0
for u in abc:
    a,b,c=u
    for i in range(l-a):
        for j in range(l-b):
            if data[i][j]!=inf:
                data[i+a][j+b]=min(data[i+a][j+b],data[i][j]+c)

k=1
ans=inf
while ma*k<l and mb*k<l:
    if data[ma*k][mb*k]!=inf:
        ans=min(ans,data[ma*k][mb*k])
    k+=1
if ans!=inf:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def examD(inf):
    N, Ma, Mb = LI()
    abc = [0,0,0]*N
    maxA = 0; maxB = 0
    for i in range(N):
        abc[i] = LI()
        if maxA<abc[i][0]:
            maxA=abc[i][0]
        if maxB<abc[i][1]:
            maxB=abc[i][1]
    dp = [[[inf]*(maxB*(N+1)+1) for _ in range(maxA*(N+1)+1)]for _ in range(N+1)]
    dp[0][0][0] = 0
    for i in range(N):
        for j in range(maxA*N+1):
            for k in range(maxB*N+1):
                dp[i+1][j][k] = min(dp[i][j][k],dp[i+1][j][k])
                dp[i+1][j+abc[i][0]][k+abc[i][1]] = min(dp[i][j+abc[i][0]][k+abc[i][1]],dp[i][j][k]+abc[i][2])
#    print(dp)
    ans = inf
    for j in range(1,maxA * N+1):
        for k in range(1,maxB * N+1):
            if j%Ma==0 and k%Mb==0:
                if j//Ma==k//Mb:
                    ans = min(ans,dp[N][j][k])
    if ans==inf:
        ans = -1
    print(ans)

Submission status: Wrong Answer

Solution code:
def examD(inf):
    N, Ma, Mb = LI()
    abc = [0,0,0]*N
    maxA = 0; maxB = 0
    for i in range(N):
        abc[i] = LI()
        if maxA<abc[i][0]:
            maxA=abc[i][0]
        if maxB<abc[i][1]:
            maxB=abc[i][1]
    dp = [[[inf]*(maxB*(N+1)+1) for _ in range(maxA*(N+1)+1)]for _ in range(N+1)]
    dp[0][0][0] = 0
    for i in range(N):
        for j in range(maxA*N+1):
            for k in range(maxB*N+1):
                dp[i+1][j][k] = dp[i][j][k]
                dp[i+1][j+abc[i][0]][k+abc[i][1]] = min(dp[i][j+abc[i][0]][k+abc[i][1]],dp[i][j][k]+abc[i][2])
#    print(dp)
    ans = inf
    for j in range(1,maxA * N+1):
        for k in range(1,maxB * N+1):
            if j%Ma==0 and k%Mb==0:
                if j//Ma==k//Mb:
                    ans = min(ans,dp[N][j][k])
    if ans==inf:
        ans = -1
    print(ans)


import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(inf)

Submission status: Wrong Answer

Solution code:
def examD(inf):
    N, Ma, Mb = LI()
    abc = [0,0,0]*N
    maxA = 0; maxB = 0
    for i in range(N):
        abc[i] = LI()
        if maxA<abc[i][0]:
            maxA=abc[i][0]
        if maxB<abc[i][1]:
            maxB=abc[i][1]
    dp = [[[inf]*(maxB*(N+1)+1) for _ in range(maxA*(N+1)+1)]for _ in range(N+1)]
    dp[0][0][0] = 0
    for i in range(N):
        for j in range(maxA*N+1):
            for k in range(maxB*N+1):
                dp[i+1][j+abc[i][0]][k+abc[i][1]] = min(dp[i][j+abc[i][0]][k+abc[i][1]],dp[i][j][k]+abc[i][2])
#    print(dp)
    ans = inf
    for j in range(1,maxA * N+1):
        for k in range(1,maxB * N+1):
            if j%Ma==0 and k%Mb==0:
                if j//Ma==k//Mb:
                    ans = min(ans,dp[N][j][k])
    if ans==inf:
        ans = -1
    print(ans)


import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(inf)

Submission status: Wrong Answer

Solution code:
def examD(inf):
    N, Ma, Mb = LI()
    abc = [0,0,0]*N
    maxA = 0; maxB = 0
    for i in range(N):
        abc[i] = LI()
        if maxA<abc[i][0]:
            maxA=abc[i][0]
        if maxB<abc[i][1]:
            maxB=abc[i][1]
    dp = [[[inf]*(maxB*(N+1)+1) for _ in range(maxA*(N+1)+1)]for _ in range(N+1)]
    dp[0][0][0] = 0
    for i in range(N):
        for j in range(maxA*N+1):
            for k in range(maxB*N+1):
                dp[i+1][j+abc[i][0]][k+abc[i][1]] = min(dp[i][j+abc[i][0]][k+abc[i][1]],dp[i][j][k]+abc[i][2])
#    print(dp)
    ans = inf
    for j in range(maxA * N):
        for k in range(maxB * N):
            if j%Ma==0 and k%Mb==0:
                if j//Ma==k//Mb:
                    ans = min(ans,dp[N][j][k])
    if ans==inf:
        ans = -1
    print(ans)


import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(inf)

Submission status: Wrong Answer

Solution code:
def examD(inf):
    N, Ma, Mb = LI()
    abc = [0,0,0]*N
    maxA = 0; maxB = 0
    for i in range(N):
        abc[i] = LI()
        if maxA<abc[i][0]:
            maxA=abc[i][0]
        if maxB<abc[i][1]:
            maxB=abc[i][1]
    dp = [[[inf]*(maxB*(N+1)+1) for _ in range(maxA*(N+1)+1)]for _ in range(N+1)]
    dp[0][0][0] = 0
    for i in range(N):
        for j in range(maxA*N+1):
            for k in range(maxB*N+1):
                dp[i+1][j+abc[i][0]][k+abc[i][1]] = min(dp[i][j+abc[i][0]][k+abc[i][1]],dp[i][j][k]+abc[i][2])
    print(dp)
    ans = inf
    for j in range(maxA * N):
        for k in range(maxB * N):
            if j%Ma==0 and k%Mb==0:
                if j//Ma==k//Mb:
                    ans = min(ans,dp[N][j][k])
    if ans==inf:
        ans = -1
    print(ans)


import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(inf)

Submission status: Wrong Answer

Solution code:
N, Ma, Mb = map(int, input().split())

INF = 10 ** 8

lst = [[INF] * 401 for i in range(401)]
lst[0][0] = 0

for _ in range(N):
    a, b, c = map(int, input().split())
    for i in range(a, 401):
        for j in range(b, 401):
            if lst[i- a][j - b] == INF:
                pass
            else:
                lst[i][j] = min(lst[i][j], lst[i - a][j - b] + c)

ans = INF
n = 400 // max(Ma, Mb)
for i in range(1, n + 1):
    ans = min(ans, lst[Ma * i][Mb * i])

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

Submission status: Wrong Answer

Solution code:
N, Ma, Mb = map(int, input().split())

INF = 10 ** 8

lst = [[INF] * 401 for i in range(401)]
lst[0][0] = 0

for _ in range(N):
    a, b, c = map(int, input().split())
    for i in range(a, 401):
        for j in range(b, 401):
            if lst[i][j] == INF:
                pass
            else:
                lst[i][j] = min(lst[i][j], lst[i - a][j - b] + c)

ans = INF
n = 400 // max(Ma, Mb)
for i in range(1, n + 1):
    ans = min(ans, lst[Ma * i][Mb * i])

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

Submission status: Wrong Answer

Solution code:
N, Ma, Mb = map(int, input().split())

INF = 10 ** 8

lst = [[INF] * 401 for i in range(401)]
lst[0][0] = 0

for _ in range(N):
    a, b, c = map(int, input().split())
    for i in range(a, 401):
        for j in range(b, 401):
            lst[i][j] = min(lst[i][j], lst[i - a][j - b] + c)

ans = INF
n = 400 // max(Ma, Mb)
for i in range(1, n + 1):
    ans = min(ans, lst[Ma * i][Mb * i])

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

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
dp=[[[10**30 for j in range(401)]for i in range(401)]for k in range(n+1)]
dp[0][0][0]=0 
l=[]
for i in range(n):
    a,b,c=map(int,input().split())
    l.append([a,b,c])
for i in range(1,n+1):
    a,b,c=l[i-1][0],l[i-1][1],l[i-1][2]
    for x in range(401):
        for y in range(401):
            if x<a or y<b:
                dp[i][x][y]=dp[i-1][x][y]
                continue 
            dp[i][x][y]=min(dp[i][x][y],dp[i-1][x-a][y-b]+c)
            
mini=10**30 
for i in range(1,40):
    mini=min(mini,dp[n][ma*i][mb*i])
if mini>=10**30 :
    print(-1)
else:
    print(mini)

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
dp=[[10**30 for j in range(401)]for i in range(401)]
dp[0][0]=0 
l=[]
for i in range(n):
    a,b,c=map(int,input().split())
    l.append([a,b,c])
for a,b,c in l:
    for x in range(401):
        for y in range(401):
            if x<a or y<b:
                continue 
            dp[x][y]=min(dp[x][y],dp[x-a][y-b]+c)
mini=10**30 
for i in range(1,40):
    mini=min(mini,dp[ma*i][mb*i])
if mini>=10**30 :
    print(-1)
else:
    print(mini)

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
dp=[[10**30 for j in range(401)]for i in range(401)]
dp[0][0]=0 
for i in range(n):
    a,b,c=map(int,input().split())
    for x in range(401):
        for y in range(401):
            if x<a or y<b:
                continue 
            dp[x][y]=min(dp[x][y],dp[x-a][y-b]+c)
mini=10**30 
for i in range(1,40):
    mini=min(mini,dp[ma*i][mb*i])
if mini>=10**30 :
    print(-1)
else:
    print(mini)

Submission status: Wrong Answer

Solution code:
n,ma,mb=map(int,input().split())
dp=[[10**9 for j in range(401)]for i in range(401)]
dp[0][0]=0 
for i in range(n):
    a,b,c=map(int,input().split())
    for x in range(401):
        for y in range(401):
            if x<a or y<b:
                continue 
            dp[x][y]=min(dp[x][y],dp[x-a][y-b]+c)
mini=10**9 
for i in range(1,40):
    mini=min(mini,dp[ma*i][mb*i])
if mini>=10**9:
    print(-1)
else:
    print(mini)