Test with custom input is giving expected output but on submitting same input gives wrong


#1

this is my code. On testing it gives correct answer. after submitting it gave wrong answer in one input. but when i tried same output in test with custom input i got correct answer.
Try it yourself.

int cost(int k,const vector &B, const vector &C, vector &memo)
{
int n=B.size();
if(memo[k]!=-1)
{
return memo[k];
}

int minc=INT_MAX;
for(int i=0;i<n;++i)
{
    if(k-B[i]>=0)
    {
        minc=min(minc, cost( k-B[i] , B,C,memo) + C[i] );
    }

}

memo[k]=minc;

return minc;
}

int Solution::solve(const vector &A, const vector &B, const vector &C) {
int n=A.size();
int capOf1=INT_MAX, maxk=0;
for(int i=0;i<n;++i)
{
if(A[i]>maxk )
{
maxk=A[i];
}
if(B[i]==1)
{
if(C[i]<capOf1)
capOf1=C[i];
}
}

int ans=0;
//cout<<maxk<<" "<<capOf1<<endl;
vector<int> memo(maxk + 1,-1);
memo[1]=capOf1;
memo[0]=0;

for(int i=0;i<n;++i)
{
    int temp=cost(A[i],B,C,memo);
    ans+=temp;
}

return ans;
}