题目描述
Problem Description
Rie likes to make cookies. She made $N$ types of cookies. She made $A_i$ cookies of type $i$ $(1 \leq i \leq N)$. In order to sell the cookies made by her, she will pack them into boxes. However, the following conditions should be satisfied:
- For every box, the types of the cookies in it should be different.
- For every box, the number of cookies in it should be equal to one of the following $M$ numbers: $B_1, B_2, \cdots, B_M$.
Write a program which, given information of cookies made by Rie and the conditions to pack the cookies into boxes, determines whether it is possible to pack all the cookies into boxes. Moreover, if it is possible to pack all the cookies into boxes, your program should output a way to pack the cookies into the minimum number of boxes.
Input Format
Read the following data from the standard input:
$N$
$A_1 \ A_2 \ \cdots \ A_N$
$M$
$B_1 \ B_2 \ \cdots \ B_M$
Output Format
If it is possible to pack all the cookies into boxes so that the conditions are satisfied, let $x$ be the number of used boxes, $c_k$ be the number of cookies in the $k$-th box $(1 \leq k \leq x)$, and $v_{k,1}, v_{k,2}, \cdots, v_{k,c_k}$ be the types of the cookies in the $k$-th box. Write these numbers to the standard output as in the following format:
$x$
$c_1 \ v_{1,1} \ v_{1,2} \ \cdots \ v_{1,c_1}$
$c_2 \ v_{2,1} \ v_{2,2} \ \cdots \ v_{2,c_2}$
$\vdots$
$c_x \ v_{x,1} \ v_{x,2} \ \cdots \ v_{x,c_x}$
Here, the number of used boxes $x$ should be the minimum possible number. If there are several ways to pack the cookies into boxes satisfying the conditions, output any one of them.
If it is impossible to pack all the cookies into boxes so that the conditions are satisfied, write $-1$ to the standard output.
Sample Input and Output
Sample Input #1
7
1 1 1 1 1 1 1
3
1 2 3
Sample Output #1
3
2 1 7
2 2 6
3 3 4 5
Sample Input #2
5
5 3 1 2 4
1
4
Sample Output #2
-1
Sample Input #3
7
5 4 4 2 1 1 1
2
2 6
Sample Output #3
7
6 1 2 3 4 5 6
2 2 1
2 3 1
2 4 1
2 7 1
2 3 2
2 3 2
Notes/Hints
Sample Explanation #1
In this sample input, it is possible to pack the $7$ cookies into $3$ boxes so that the conditions are satisfied as follows:
- Pack cookies of types $1, 7$ into the first box. Pack one cookie for each type.
- Pack cookies of types $2, 6$ into the second box. Pack one cookie for each type.
- Pack cookies of types $3, 4, 5$ into the third box. Pack one cookie for each type.
Your program is judged as correct if it outputs the above way to pack the cookies because it is impossible to pack the $7$ cookies into less than or equal to $2$ boxes so that the conditions are satisfied. There are other ways to pack the cookies which are judged as correct.
This sample input satisfies the constraints of Subtasks 1, 3, 4, 5, 6.
Sample Explanation #2
In this sample input, it is impossible to pack the $15$ cookies into boxes so that the conditions are satisfied.
Therefore, output $-1$.
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5, 6.
Sample Explanation #3
This sample input satisfies the constraints of Subtasks 4, 5, 6.
Data Range
For all test data, it is guaranteed that $1 \leq N \leq 15,000$, $A_i \geq 1$ $(1 \leq i \leq N)$, $A_1 + A_2 + \cdots + A_N \leq 15,000$, $1 \leq M \leq N$, $1 \leq B_j \leq N$ $(1 \leq j \leq M)$, $B_j < B_{j+1}$ $(1 \leq j \leq M-1)$, and all inputs are integers.
| Subtask Number | Score | Constraints |
|---|---|---|
| 1 | 6 | $N \leq 500$, $A_i = 1$ $(1 \leq i \leq N)$ |
| 2 | 7 | $N \leq 500$, $M = 1$ |
| 3 | 12 | $A_1 + A_2 + \cdots + A_N \leq 15$ |
| 4 | 45 | $A_1 + A_2 + \cdots + A_N \leq 500$ |
| 5 | 15 | $A_1 + A_2 + \cdots + A_N \leq 3,000$ |
| 6 | 15 | No additional constraints |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分