input: Write a python function to optimize the cost of a given set of knapsack items.
  assert knapsack([("A", 4, 12), ("B", 2, 1), ("C", 2, 2), ("D", 1, 1), ("E", 10, 4)], 15)==["A", "C", "D", "E"]
  assert knapsack([("A", 1, 1), ("B", 2, 2), ("C", 3, 4)], 5)==["B", "C"]
  assert knapsack([("A", 1, 1), ("B", 3, 4), ("C", 4, 5), ("D", 5, 7)], 7)==["B", "C"]
output: def knapsack(items, capacity):
      n = len(items)
      dp = [[0] * (capacity + 1) for _ in range(n + 1)]
      keep = [[0] * (capacity + 1) for _ in range(n + 1)]
  
      for i in range(1, n + 1):
          name, weight, value = items[i-1]
          for w in range(1, capacity + 1):
              if weight <= w:
                  if value + dp[i-1][w-weight] > dp[i-1][w]:
                      dp[i][w] = value + dp[i-1][w-weight]
                      keep[i][w] = 1
                  else:
                      dp[i][w] = dp[i-1][w]
              else:
                  dp[i][w] = dp[i-1][w]
  
      result = []
      w = capacity
      for i in range(n, 0, -1):
          if keep[i][w] == 1:
              result.append(items[i-1][0])
              w -= items[i-1][1]
  
      return sorted(result)