The military intelligence of one country found out that N (N < 100) battle ships of neighboring enemy country are situated in M rows (1 < M < 10). The intelligence knows the lengths l1, l2,
, lN of the battle ships which are whole numbers in the interval [1, 100], and wants to know in which rows the ships are situated. The only thing that is known about the M rows are their lengths — L1, L2,
, LM. Assume that the ships touch their neighbours in the rows and that every row contains at least one ship. Write program that will find one possible ordering of the ships in rows.
Input
The first line of the input contains N and M. The next N lines contain the lengths of the ships. The next M lines contain the lengths of the rows.
Output
The output should contain M pairs of lines. The first line of each pair should contain the amount of the ships in the current row, the following line should contain the lengths of the ships from the current row. The order of the M row descriptions should be the same as the order in which the rows are given in the input.
Sample
| input | output |
|---|
5 2
4
10
2
5
3
11
13
| 3
5 4 2
2
10 3
|
Notes
This problem is the same as 1115 "
Ships" but with harder tests.
The total number of tests in this problem is limited to 20 tests. It means if new good tests are discovered, they couldn’t be simply added but should replace some of the old ones.
If you’re stuck, don’t spend time on figuring out the test data and hyperoptimizing, because the test could be replaced with a similar one any time. Instead, detect that your heuristics fail and launch another one in this case. There is no universal test in the test data that makes all the heuristics fail at the same time.
Problem Author: Prepared by Vladimir Yakovlev