Company: Deshaw_28thjune
Difficulty: medium
Minimize Cost Difference A shop sells n items, and the cost of the i -th item is cost[i] . The shopkeeper wants to bring the most expensive and the cheapest items closer together, but prices may only move slowly, so the change is spread over m days. On each of the m days the shopkeeper performs both of these operations: decrease the cost of one item that currently has the maximum cost by 1 ; increase the cost of one item that currently has the minimum cost by 1 . When several items share the maximum (or minimum) cost, the shopkeeper chooses which one of them to change. Both operations are decided from the costs at the start of the day and are applied to two different items (inferred -- when every item has the same cost, one item goes down by 1 and a different item goes up by 1; this is what makes cost = [5, 5], m = 1 give 2) . With a single item ( n = 1 ) that item is both the maximum and the minimum, so its cost never changes. Find the minimum possible difference between the maximum a