Break-even with a sales mix and step costs
A bakery chain in Sao Paulo sells several products in a fixed sales mix: every "bundle" of sales contains a set number of units of each product (for example 5 loaves, 3 cakes and 2 boxes of cookies). Besides the fixed monthly cost, the chain must rent one extra storage unit for every full block of K units sold, and each such unit costs S per month. So the cost is not a straight line.
For N bundles: units sold = N times the sum of the weights, profit = N times the contribution of one bundle (sum of weight times (price minus variable cost)), minus the fixed cost, minus S * floor(units / K).
Task: line 1: fixed cost F. Line 2: K S. Line 3: the number of products p. Then p lines name price cost weight (price and cost have up to 2 decimals, weight is an integer). Find the smallest number of bundles N (from 0 up to 200000) with profit of zero or more. Print Bundles: N, then for each product in input order name: units, then Revenue: R and Profit: P (2 decimals). If no N up to 200000 works, print NEVER.
Sample tests
Input
4500 500 900 3 Loaf 3.50 1.20 5 Cake 18.00 9.50 3 Cookies 6.25 2.10 2
Expected output
Bundles: 140 Loaf: 700 Cake: 420 Cookies: 280 Revenue: 11760.00 Profit: 42.00
Input
0 100 50 1 Bun 1.00 0.40 1
Expected output
Bundles: 0 Bun: 0 Revenue: 0.00 Profit: 0.00
Your answer is also checked against 4 hidden tests.
Need a hint?
Because of the step costs, profit does not always rise with N. Test each N in order and stop at the first one that works.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
