input: Write a function to calculate the maximum possible revenue from the items with given weights and values. Given a list of weights and corresponding values, and a total capacity of a knapsack, the function should return the maximum value that can be obtained by selecting items without exceeding the capacity.
  
  def knapsack(weights, values, capacity):
      n = len(weights)
      K = [[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:
                  K[i][w] = 0
              elif weights[i - 1] <= w:
                  K[i][w] = max(values[i - 1] + K[i - 1][w - weights[i - 1]], K[i - 1][w])
              else:
                  K[i][w] = K[i - 1][w]
      return K[n][capacity]
  
  assert knapsack([2, 1, 3], [4, 2, 3], 5) == 7
  assert knapsack([1, 2, 3], [1, 2, 3], 4) == 5
  assert knapsack([1, 2, 3], [6, 10, 12], 5) == 22
  assert knapsack([], [], 10) == 0
  assert knapsack([1, 3, 4, 5], [1, 4, 5, 7], 7) == 9
output: def knapsack(weights, values, capacity):
      n = len(weights)
      K = [[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:
                  K[i][w] = 0
              elif weights[i - 1] <= w:
                  K[i][w] = max(values[i - 1] + K[i - 1][w - weights[i - 1]], K[i - 1][w])
              else:
                  K[i][w] = K[i - 1][w]
      return K[n][capacity]