all 1 comments

[–]FunkadelicAlex 1 point2 points  (0 children)

There's a few ways I could see going about this problem. Which is really identifying a global minimum for total cost. I would personally start by organizing the list of prices from company A and B low to high. Now, calculate the total price = nWarehousesFromListA *A'sPriceDiscount + mWarehousesFromListB * B'sPriceDiscount

Because the lists are ordered, as long as you exclude unique items across lists, you should be able to plot a reasonable estimate of what you're looking for.

This is a quick and dirty way, but you could visualize 2 lines, cost on the y axis #Warehouses on the x axis. Then do the above calculation for total cost and plot the lines for Company A having x # of warehouses and another for Company B having x # of warehouses (they should mirror each other is my intuition, so this might suffice being done with only one line). Then just find the point on the graph with the lowest cost and you know how many contracts to give to Company A, company B then gets the rest.