Devil's Hell deLivery
Time limit2sMemory limit1024 MB
Assign K items to N trucks over the fewest steps so each truck's load per step stays within its capacity, and print the assignment.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
Devil's Hell deLivery company delivers literally everything: boxes, packages, packets, datagrams et cetera.
The delivery process from city A to city B works as follows. There are trucks and items. The capacity of truck number is . The weight of item number is . The trucks make one or more delivery steps.
During one step, some items are loaded into some trucks. Items cannot be split. The total weight of the items assigned to each truck must not exceed that truck's capacity. All trucks depart simultaneously.
At the end of each step, all trucks return to the place where they started. If any items are left, another step is performed.
Distribute the items among steps and trucks so that the number of steps is minimized.
Input
The input contains up to a hundred test cases.
Each test case starts with a line containing two integers and (, ): the number of trucks and the number of items. The next line contains integers (): the capacities of the trucks. The next line contains integers (): the weights of the items.
Output
For each test case, if the delivery is impossible, write a single line containing the integer .
Otherwise, write a line containing a single integer : the number of steps required. This number must be minimized. Then write lines describing the steps. Each step description starts with an integer , the number of items delivered during the step, followed by pairs . Each pair means that item is assigned to truck .
If more than one optimal answer exists, write any one of them.