Wrong output?can anyone find the bug?


#1

int Solution::solve(const vector &A, const vector &B, const vector &C) {
vectorf=A;
vectordish,cost;
dish=B,cost=C;

int n=cost.size();
int sum=*max_element(f.begin(),f.end());
int dp[n+1][sum+1];
for(int i=0;i<=n;i++){dp[i][0]=0;}
for(int j=0;j<=sum;j++){dp[0][j]=INT_MAX/10;}
for(int i=1;i<=n;i++)
{for(int j=1;j<=sum;j++)
{if(dish[i-1]<=j)
{
dp[i][j]=min(cost[i-1]+dp[i][j-dish[i-1]],dp[i-1][j]);
}
else{dp[i][j]=dp[i-1][j];}
}

}
int val=0;
for(int i=0;i<n;i++)
{
val+=dp[n][f[i]];
}
return val;
}