program table;
const maxn=500;
var g:array[0..maxn,0..maxn]of longint;
que,d:array[0..maxn]of longint;
v:array[0..maxn]of boolean;
n,m:longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
function bfs(s,t:longint):boolean;
var i,u,l,r:longint;
begin
fillchar(que,sizeof(que),0);
fillchar(v,sizeof(v),false);
fillchar(d,sizeof(d),0);
l:=0;r:=1;que[l]:=s;v[s]:=true;
while l<r do
begin
u:=que[l];
for i:=0 to n+m+1 do
if (g[u][i]>0)and(not v[i]) then
begin
que[r]:=i;
inc(r);
d[i]:=d[u]+1;
v[i]:=true;
end;
inc(l);
end;
exit(v[t]);
end;
function dfs(p,a,t:longint):longint;
var f,flow,i:longint;
begin
if (p=t)or(a=0) then exit(a);
flow:=0;
for i:=0 to n+m+1 do
if (g[p][i]>0)and(d[i]=d[p]+1)then
begin
f:=dfs(i,min(g[p][i],a),t);
if f=0 then continue;
inc(flow,f);
inc(g[i][p],f);
dec(g[p][i],f);
dec(a,f);
if a=0 then break;
end;
exit(flow);
end;
function dinic(s,t:longint):longint;
var ans:longint;
begin
ans:=0;
while bfs(s,t) do
ans:=ans+dfs(s,maxlongint,t);
exit(ans);
end;
procedure init;
var i,j,tot1,tot2,tot3:longint;
begin
read(n,m);
fillchar(g,sizeof(g),255);
tot1:=0;tot2:=0;
for i:=1 to n do
for j:=1 to m do
begin
g[i][j+n]:=1;
g[j+n][i]:=0;
end;
for i:=1 to n do
begin
read(j);
g[0][i]:=j;
g[i][0]:=0;
tot1:=tot1+j;
end;
for i:=1 to m do
begin
read(j);
g[i+n][n+m+1]:=j;
g[n+m+1][i+n]:=0;
tot2:=tot2+j;
end;
if tot2<tot1 then begin write(0);exit;end;
tot3:=dinic(0,n+m+1);
if tot3<>tot1 then begin write(0);exit;end;
writeln(1);
for i:=1 to n do
begin
for j:=1 to m do
if g[i][j+n]=0 then write(j,' ');
writeln;
end;
end;
begin
assign(input,'table9.in');reset(input);
assign(output,'f.out');rewrite(output);
init;
close(input);close(output);
end.
评论