ABC classification for a Rotterdam warehouse
A distribution centre in Rotterdam stocks thousands of spare parts. Management applies ABC analysis (the Pareto idea): a few items carry most of the yearly value and deserve tight control.
Task: line 1 is the number of items n. Then n lines sku units cost_cents (sku is text without spaces, units and cost_cents are non-negative integers). The yearly value of an item is units * cost_cents. Sort the items by value descending, ties by sku ascending (plain string order). Walk down the sorted list keeping before, the total value of the items already passed. An item is class A if before is strictly less than 80% of the grand total, otherwise class B if before is strictly less than 95% of the grand total, otherwise class C. Compare using integers only (before * 100 < 80 * total). Print one line per item sku value class in the sorted order, then a final line A=x B=y C=z with the class counts.
Sample tests
Input
8 BRK-01 1200 4500 FLT-22 300 800 BLT-05 5000 120 SEN-90 40 25000 GSK-11 9000 35 PMP-07 150 9000 SCR-33 20000 8 VLV-44 60 1500
Expected output
BRK-01 5400000 A PMP-07 1350000 A SEN-90 1000000 A BLT-05 600000 B GSK-11 315000 B FLT-22 240000 B SCR-33 160000 C VLV-44 90000 C A=3 B=3 C=2
Input
3 Q 100 10 P 100 10 R 100 10
Expected output
P 1000 A Q 1000 A R 1000 A A=3 B=0 C=0
Your answer is also checked against 3 hidden tests.
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.
