All test cases not passed


#1

what is wrong with my solution?
int Solution::solve(const vector &A, const vector &B, const vector &C) {
int ans = 0,m = B.size(),i,j;
for(int k=0;k<A.size();k++)
{
int c = A[k];
int dp[m][c+1];
for(i=0;i<m;i++)
dp[i][0] = 0;
for(i=1;i<=c;i++)
{
if(i%B[m-1] ==0)
dp[m-1][i] = (i/B[m-1])*C[m-1];
else
dp[m-1][i] = -1;
}
for(i=m-2;i>=0;i–)
{
for(j=1;j<=c;j++)
{
// dp[i][j] = -1;
if(j>= B[i])
{
int col = j-B[i];
if(col >=0 && dp[i][col]!=-1)
dp[i][j] = min(dp[i+1][j], C[i]+ dp[i][col]);
else
dp[i][j] = dp[i+1][j];
}
else
dp[i][j] = dp[i+1][j];
}
}
// cout<<ans<<" ";
ans += dp[0][c];
}
return ans;
}