#include <iostream> #include <algorithm> using namespace std; int input1, input2; int i, j; struct Team { int number; int memberNum; int person[101]; }; struct Table { int number; int chairNum; int chair[101]; }; Team team[71]; Table nTable[51]; bool compareTeam(const Team &a, const Team &b) { return a.memberNum>b.memberNum; } bool compareTeam2(const Team &a, const Team &b) { return a.number<b.number; } bool compareTable(const Table &a, const Table &b) { return a.chairNum>b.chairNum; } void printTeam() { cout << "1" <<endl; for(i=1; i<input1+1; i++) { for(j=1; j<team[i].memberNum+1; j++) cout << team[i].person[j] << " "; cout <<endl; } } bool matchingTable() { for(i=1; i<input1+1; i++) { for(j=1; j<team[i].memberNum+1; j++) { if(team[i].memberNum>input2) return false; if(nTable[j].chairNum>0) { nTable[j].chairNum--; team[i].person[j] = nTable[j].number; } else return false; } sort(&team[i].person[1], &team[i].person[team[i].memberNum+1]); } return true; } int main() { while(cin >> input1 >> input2) { if(input1==0 && input2==0) break; for(i=1; i<input1+1; i++) { cin >> team[i].memberNum; team[i].number=i; } for(i=1; i<input2+1; i++) { cin >> nTable[i].chairNum; nTable[i].number=i; } sort(&team[1], &team[input1+1], compareTeam); sort(&nTable[1], &nTable[input2+1], compareTable); if(matchingTable()) { sort(&team[1], &team[input1+1], compareTeam2); printTeam(); } else cout << "0" <<endl; } return 0; }