因为切的蚯蚓一定是越来越短的,所以开三个队列,每次在三个队首找一个最长的,切开后放到第二队和第三队的队尾,能保证三个队列都单调减。
var
a:array[1..3,0..8000000] of longint;
p,q:array[1..3] of longint;
n,m,pl,u,v,t,i,j,cs,csj,cnt,plus:longint;
procedure swap(var a,b:longint);
var t:longint;
begin t:=a;a:=b;b:=t; end;
procedure sort(l,r:longint);
var
i,j,e:longint;
begin
i:=l;j:=r;e:=a[1][(l+r)>>1];
repeat
while a[1][i]>e do inc(i);
while e>a[1][j] do dec(j);
if not (i>j) then
begin
swap(a[1][i],a[1][j]);
inc(i);dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
read(n,m,pl,u,v,t);
p[1]:=1;p[2]:=1;p[3]:=1;
q[1]:=n;q[2]:=0;q[3]:=0;
for i:=1 to n do read(a[1][i]);
sort(1,n);
cnt:=0;plus:=0;
for i:=1 to m do
begin
cs:=-1;
for j:=1 to 3 do
if ((p[j]<=q[j])and(a[j][p[j]]+plus>cs))
then begin csj:=j;cs:=a[j][p[j]]+plus; end;
inc(cnt);
if (cnt=t) then
begin
write(cs,' ');
cnt:=0;
end;
inc(p[csj]);
inc(plus,pl);
inc(q[2]);a[2][q[2]]:=int64(cs) * u div v - plus;
inc(q[3]);a[3][q[3]]:=cs - (a[2][q[2]] + plus) - plus;
end;
writeln;
cnt:=0;
for i:=1 to n+m do
begin
cs:=-1;
for j:=1 to 3 do
if ((p[j]<=q[j])and(a[j][p[j]]+plus>cs))
then begin csj:=j;cs:=a[j][p[j]]+plus; end;
inc(p[csj]);
inc(cnt);
if (cnt=t) then
begin
write(cs,' ');
cnt:=0;
end;
end;
writeln;
end.