Welcome To SDIBT ACM-ICPC Online Judge

VIRTUAL JUDGE Recent Contest F.A.Qs Discuss Home ProblemSet Status Ranklist 4 Contest LoginRegister Exam
Problem 1092. -- The Grand Dinner

The Grand Dinner

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 4  Solved: 2
[Submit][Status][Discuss]

Description

Each team participating in this year's ACM World Finals is expected to attend the grand banquet arranged for after the award ceremony. To maximize the amount of interaction between members of different teams, no two members of the same team will be allowed to sit at the same table. Given the number of members on each team (including contestants, coaches, reserves, and guests) and the seating capacity of each table, determine whether it is possible for the teams to sit as described. If such an arrangement is possible, output one such seating assignment. If there are multiple possible arrangements, any one is acceptable.

Input

The input file may contain multiple test cases. The first line of each test case contains two integers, 1<=M<=70 and 1<=N<=50, denoting the number of teams and tables, respectively. The second line of each test case contains M integers, where the ith integer mi indicates the number of members of team i. There are at most 100 members of any team. The third line contains N integers, where the jth integer nj, 2<=nj<=100, indicates the seating capacity of table j. A test case containing two zeros for M and N terminates the input.

Output

For each test case, print a line containing either 1 or 0, denoting whether there exists a valid seating arrangement of the team members. In case of a successful arrangement, print M additional lines where the ith line contains a table number (from 1 to N) for each of the members of team i.

Sample Input

4 5
4 5 3 5
3 5 2 6 4
4 5
4 5 3 5
3 5 2 6 3
0 0

Sample Output

1
1 2 4 5
1 2 3 4 5
2 4 5
1 2 3 4 5
0

HINT

Source

[Submit][Status][Discuss]

HOME Back

한국어 中文 English
All Copyright Reserved 2008-2010 SDIBT TEAM
GPL2.0 2003-2010 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin