算法:模拟
很裸的一道模拟题了,不解释了……
program VJ1445;
const
maxn=100000;
var
n,m:longint;
a,b,ans,d,dd:array [0..maxn] of longint;
procedure init;
var
i:longint;
begin
fillchar(ans,sizeof(ans),0);
readln(n,m);
for i:=1 to n do read(a[i]);
for i:=1 to m do
begin
read(b[i]);
d[i]:=i;
end;
end;
procedure qsort1(l,r:longint);
var
i,j,t1,t:longint;
begin
i:=l;
j:=r;
t1:=a[(l+r) shr 1];
repeat
while a[i]>t1 do inc(i);
while a[j]<t1 do dec(j);
if i<=j then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort1(i,r);
if l<j then qsort1(l,j);
end;
procedure qsort2(l,r:longint);
var
i,j,t1,t:longint;
begin
i:=l;
j:=r;
t1:=b[(l+r) shr 1];
repeat
while b[i]>t1 do inc(i);
while b[j]<t1 do dec(j);
if i<=j then
begin
t:=b[i];
b[i]:=b[j];
b[j]:=t;
t:=d[i];
d[i]:=d[j];
d[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort2(i,r);
if l<j then qsort2(l,j);
end;
procedure teemp;
var
i:longint;
begin
for i:=1 to m do dd[d[i]]:=i;
end;
procedure main;
var
i:longint;
begin
for i:=1 to n do inc(ans[((i-1) mod m)+1],a[i]);
for i:=1 to m do write(ans[dd[i]],' ');
end;
begin
assign(input,'VJ1445.in'); reset(input);
assign(output,'VJ1445.out'); rewrite(output);
init;
qsort1(1,n);
qsort2(1,m);
teemp;
main;
close(input); close(output);
end.