Under construction

Still being built. Things may change

Devil's Hell deLivery

Time limit2sMemory limit1024 MB

Summary
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 NN trucks and KK items. The capacity of truck number ii is cic_i. The weight of item number jj is wjw_j. 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 NN and KK (1≤N≤51 \le N \le 5, 1≤K≤91 \le K \le 9): the number of trucks and the number of items. The next line contains NN integers c1,…,cNc_1, \ldots, c_N (1≤ci≤1081 \le c_i \le 10^8): the capacities of the trucks. The next line contains KK integers w1,…,wKw_1, \ldots, w_K (1≤wi≤1081 \le w_i \le 10^8): the weights of the items.

Output

For each test case, if the delivery is impossible, write a single line containing the integer −1-1.

Otherwise, write a line containing a single integer SS: the number of steps required. This number must be minimized. Then write SS lines describing the steps. Each step description starts with an integer IiI_i, the number of items delivered during the step, followed by IiI_i pairs aja_j bjb_j. Each pair means that item aja_j is assigned to truck bjb_j.

If more than one optimal answer exists, write any one of them.

Examples1

  1. Example 1

    Input
    2 4
    10 20
    5 5 5 5
    2 1
    10 10
    20
    
    Expected output
    1
    4 1 1 2 1 3 2 4 2
    -1