题目描述
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.
输入
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.
输出
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.
样例输入
4 5
4 5 3 5
3 5 2 6 4
4 5
4 5 3 5
3 5 2 6 3
0 0
样例输出
1
1 2 4 5
1 2 3 4 5
2 4 5
1 2 3 4 5
0
参考代码
暂无
解析
暂无