#K48217. Product Distribution Challenge
Product Distribution Challenge
Product Distribution Challenge
You are given the number of retail stores and a list of products with their quantities. Your task is to distribute each product equally among the stores such that the leftover products are minimized. For each product, every store receives \(\lfloor \frac{q}{n} \rfloor\) units and the remaining \(q \mod n\) units are left over.
Input Format: The first line contains an integer n representing the number of stores. The second line contains an integer m, the number of products. The following m lines each contain a product name (a single word) and its quantity.
Output Format: For each product, output a line in the format: ProductName: d r
, where d
is the number of items each store receives and r
is the leftover.
inputFormat
The input is received from standard input (stdin) and consists of:
- An integer n representing the number of stores.
- An integer m representing the number of products.
- m subsequent lines, each containing a product name (a single word) and an integer quantity, separated by a space.
outputFormat
For each product provided in the input (in the same order), print one line to standard output (stdout) in the format:
ProductName: d r
where:
d = \(\lfloor \frac{quantity}{n} \rfloor\)
r = quantity \mod n
3
4
Apples 14
Bananas 15
Cherries 9
Dates 27
Apples: 4 2
Bananas: 5 0
Cherries: 3 0
Dates: 9 0
</p>