input: Write a function to calculate the maximum possible revenue from the items with given weights and values. The function should implement the knapsack algorithm to determine the maximum value that can be obtained without exceeding a given weight capacity.
  
  def knapsack(weights, values, n, W):
      K = [[0 for x in range(W+1)] for x in range(n+1)]
      for i in range(n+1):
          for w in range(W+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][W]
  
  assert knapsack([2, 1, 3], [4, 2, 3], 3, 5) == 7
  assert knapsack([2, 3, 4, 5], [3, 4, 5, 6], 4, 5) == 7
  assert knapsack([1, 2, 3], [60, 100, 120], 3, 5) == 220
  assert knapsack([10, 20, 30], [60, 100, 120], 3, 50) == 220
  assert knapsack([], [], 0, 50) == 0
output: def knapsack(weights, values, n, W):
      K = [[0 for x in range(W+1)] for x in range(n+1)]
      for i in range(n+1):
          for w in range(W+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][W]