시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB67171625.806%

문제

Rie likes to make cookies. She made $N$ types of cookies. She made $A_i$ cookies of type $i$ ($1 ≤ i ≤ 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, \dots , 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.

입력

Read the following data from the standard input.

$N$

$A_1$ $A_2$ $\cdots$ $A_N$

$M$

$B_1$ $B_2$ $\cdots$ $B_M$

출력

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 ≤ k ≤ x$), and $v_{k,1}, v_{k,2}, \dots , 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.

제한

  • $1 ≤ N ≤ 15\,000$.
  • $A_i ≥ 1$ ($1 ≤ i ≤ N$).
  • $A_1 + A_2 + \cdots + A_N ≤ 15\,000$.
  • $1 ≤ M ≤ N$.
  • $1 ≤ B_j ≤ N$ ($1 ≤ j ≤ M$).
  • $B_j < B_{j+1}$ ($1 ≤ j ≤ M - 1$).
  • Given values are all integers.

서브태스크

번호배점제한
16

$N ≤ 500$, $A_i = 1$ ($1 ≤ i ≤ N$).

27

$N ≤ 500$, $M = 1$.

312

$A_1 + A_2 + \cdots + A_N ≤ 15$.

445

$A_1 + A_2 + \cdots + A_N ≤ 500$.

515

$A_1 + A_2 + \cdots + A_N ≤ 3\,000$.

615

No additional constraints.

예제 입력 1

7
1 1 1 1 1 1 1
3
1 2 3

예제 출력 1

3
2 1 7
2 2 6
3 3 4 5

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

5
5 3 1 2 4
1
4

예제 출력 2

-1

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

7
5 4 4 2 1 1 1
2
2 6

예제 출력 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

This sample input satisfies the constraints of Subtasks 4, 5, 6.

채점 및 기타 정보

  • 예제는 채점하지 않는다.