#C1810. Warehouse Package Distribution
Warehouse Package Distribution
Warehouse Package Distribution
You are given a warehouse with several storage racks, each with a specified capacity. Additionally, a list of packages is provided where each package is defined by its weight and priority. Your task is to distribute the packages among the racks according to the following rules:
- Sort the packages in descending order of priority. For packages with the same priority, sort them in ascending order of weight. In other words, for two packages \(a\) and \(b\), the sorting order is determined by \( (-priority, weight) \).
- Assign the sorted packages to the racks sequentially: fill the first rack until its capacity is reached, then continue with the next rack, and so on.
The final output should be a list of lists where each inner list corresponds to a rack and contains the packages assigned to it in the order they were placed. Each package should be represented as a tuple \((weight, priority)\).
Input Format:
The input is read from standard input (stdin) and follows this format:
- The first line contains an integer \(n\), the number of racks.
- The second line contains \(n\) space-separated integers representing the capacities of each rack.
- The third line contains an integer \(m\), the number of packages.
- The next \(m\) lines each contain two space-separated integers representing the weight and priority of a package.
Output Format:
Output the final distribution of packages as a list of lists in Python list format. Each inner list represents one rack and includes packages formatted as \((weight, priority)\).
inputFormat
The first line contains an integer \(n\) (the number of racks). The second line contains \(n\) space-separated integers which represent the capacity of each rack. The third line contains an integer \(m\) (the number of packages). The following \(m\) lines each contain two integers (\(weight\) and \(priority\)) for a package.
outputFormat
Output a list of lists in Python list format. Each inner list corresponds to a rack and contains the packages (in the order assigned) formatted as \((weight, priority)\).
## sample3
3 2 1
6
8 5
5 2
2 2
7 5
10 1
3 2
[[(7, 5), (8, 5), (2, 2)], [(3, 2), (5, 2)], [(10, 1)]]