Cutting Metal Rods

Company: Cognizant ace_13may

Difficulty: medium

Problem Statement

Cutting Metal Rods A construction company has a pile of surplus metal rods of arbitrary integer lengths. A contractor will only buy rods that all have the same exact integer length, called the saleLength . Every rod sold at that length earns saleLength * salePrice . Rods may be cut to produce more sellable pieces, but each cut costs costPerCut . Any material that does not end up as a piece of exactly saleLength is discarded, and a rod may also be left alone or thrown away entirely. If the chosen saleLength produces totalUniformRods sellable pieces after totalCuts cuts, the profit is totalProfit = totalUniformRods saleLength salePrice - totalCuts * costPerCut Choose the single saleLength that maximises totalProfit , and report that profit. How cutting works A rod of length L cut into pieces of length s : taking k pieces off the rod costs k cuts, because each piece is separated by one cut; the last cut is not needed when nothing is left over, so if k * s == L the cost is k - 1 cuts; a ro