var
nn,vv:array[1..20000] of longint;
v:array[1..400000] of longint;
num:array[1..400000] of int64;
f:array[0..20000] of longint;
yl:array[1..400000] of longint;
use:array[1..20000] of longint;
te,tail,mon,n,hx,i,j,k,ans:longint;
procedure init;
begin
readln(n);
for i:=1 to n do
read(vv[i]);
readln;
for i:=1 to n do
read(nn[i]);
readln(mon);
tail:=0;
for i:=1 to n do
begin
te:=1;
while nn[i]>te do
begin
nn[i]:=nn[i]-te;
inc(tail);
v[tail]:=vv[i]*te;
num[tail]:=te;
yl[tail]:=i;
te:=te*2;
end;
inc(tail);
v[tail]:=vv[i]*nn[i];
num[tail]:=nn[i];
yl[tail]:=i;
end;
for i:=1 to 20000 do f[i]:=maxlongint;
for i:=1 to tail do
for j:=mon downto v[i] do
if f[j]>f[j-v[i]]+num[i] then f[j]:=f[j-v[i]]+num[i];
te:=mon;
while te<>0 do
for i:=tail downto 1 do
begin
if te=0 then break;
if (te>=v[i])and(f[te-v[i]]+num[i]=f[te])
then
begin
inc(use[yl[i]],num[i]);
te:=te-v[i];
end;
end;
end;
begin
assign(input,'pay.in');
reset(input);
assign(output,'pay.out');
rewrite(output);
init;
writeln(f[mon]);
for i:=1 to n do
write(use[i],' ');
close(output);
end.