Company: Microsoft_17july
Difficulty: medium
Maximum Alloy Units from Stock and Budget Problem Description A foundry produces a single alloy from n types of metal. The recipe is fixed: making one unit of the alloy consumes exactly composition[i] units of metal i , for every i . Metal types are never interchangeable - a shortage of one metal cannot be covered by a surplus of another. The foundry already holds stock[i] units of metal i . It may also buy additional units of any metal from a supplier at cost[i] per unit. The supplier's stock is unlimited. Total spending must not exceed budget . Determine the largest whole number of alloy units the foundry can produce. To produce x units of alloy, metal i is needed in total quantity composition[i] * x . The existing stock covers part of that, so the foundry must buy max(0, composition[i] * x - stock[i]) units of metal i , and the money required is sum over i of cost[i] * max(0, composition[i] * x - stock[i]) x units can be produced exactly when this amount is at most budget . (inferre