P9339 [JOISC 2023] Cookies
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.
Explanation/Hint
**【样例解释 #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.
**【样例解释 #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.
**【样例解释 #3】**
This sample input satisfies the constraints of Subtasks 4, 5, 6.
**【数据范围】**
对于所有测试数据,满足 $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$),保证所有输入均为整数。
| **子任务编号** | **分值** | **限制** |
| :----------: | :----------: | :----------: |
| $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 3000$ |
| $6$ | $15$ | 没有额外的限制 |