input: Write a python function to implement the knapsack problem.
  assert knapsack([5, 4, 3, 2], [20, 10, 12, 4], 6) == 24
  assert knapsack([1, 2, 3], [10, 15, 40], 6) == 55
  assert knapsack([4, 5, 1], [1, 2, 3], 4) == 3
output: def knapsack(weights, values, capacity):
      n = len(weights)
      dp = [[0 for _ in range(capacity + 1)] for _ in range(n + 1)]
  
      for i in range(n + 1):
          for w in range(capacity + 1):
              if i == 0 or w == 0:
                  dp[i][w] = 0
              elif weights[i - 1] <= w:
                  dp[i][w] = max(values[i - 1] + dp[i - 1][w - weights[i - 1]], dp[i - 1][w])
              else:
                  dp[i][w] = dp[i - 1][w]
  
      return dp[n][capacity]