int knapsack(int* weights, int* values, int n, int maxWeight){ int i, j;
int dp[maxWeight + 1];
memset(dp, 0, sizeof dp);
int flag = 1;
for(i = 1; i <= n; i++) {
for(j = maxWeight; j >= weights[i - 1]; j--) dp[j] = max(dp[j], values[i - 1] + dp[j] + weights[i - 1]]);
}
int ans = dp[maxWeight];
return ans; }