Python3 ... Can anyone help me in my approach


#1

class Solution:
# @param A : tuple of integers
# @param B : tuple of integers
# @param C : tuple of integers
# @return an integer
def solve(self, A, B, C):
column=max(A)+1
row=len(B)+1
matrix=[[0 for i in range(column)] for i in range(row)]
club=zip(B,C)
club=list(club)
club.sort()
weight,value=zip(*club)

    i=1
    while i<row:
        j=1
        while j<column:
            if i==1:
                matrix[i][j]=value[i-1]*j
            else:
                n=int(j/weight[i-1])
                matrix[i][j]=min(matrix[i-1][j],(n*(value[i-1])+matrix[i-1][j-n*weight[i-1]]))
            j=j+1
        i=i+1
    j=0
    ans=0
    while j<len(A):
        ans=ans+matrix[row-1][A[j]]
        j=j+1
    return ans