Pagini recente » Cod sursa (job #569201) | Cod sursa (job #2608474) | Cod sursa (job #280737) | Cod sursa (job #804373) | Cod sursa (job #315802)
Cod sursa(job #315802)
program pascal;
var f,g:text; t:array[1..50000] of byte; x,p:array[1..1000] of longint;
max,i,k,j,n,aux,c:longint;
procedure citire;
begin
assign(f,'economie.in'); reset(f);
assign(g,'economie.out'); rewrite(g);
readln(f,n);
max:=0;
for i:=1 to n do readln(f,x[i]);
max:=50000;
for i:=1 to max do t[i]:=1;
close(f);
end;
procedure sort(s,d:longint);
var a,b,aux,ia:longint;
begin
a:=s; b:=d;
repeat
while x[a]<x[b] do b:=b-1;
aux:=x[a]; x[a]:=x[b]; x[b]:=aux; ia:=1; a:=a+1;
if a<b then
begin
while x[a]<x[b] do a:=a+1;
if a<>b then
begin
aux:=x[a]; x[a]:=x[b]; x[b]:=aux; ia:=0; b:=b-1;
end;
end;
until b<=a;
if a-ia>s then sort(s,a-ia);
if a-ia+1<d then sort(a-ia+1,d);
end;
procedure sorte;
begin
k:=0;
for j:=1 to n do
begin
if t[x[j]]=1 then
begin
k:=k+1; p[k]:=x[j]; t[x[j]]:=0;
end;
for i:=1 to max do
if t[i]=0 then
begin
c:=i+x[j];
if (c<=max) then t[c]:=0;
end;
end;
end;
procedure afisare;
begin
writeln(g,k);
for i:=1 to k do writeln(g,p[i]);
close(g);
end;
begin
citire;
sort(1,n);
sorte;
afisare;
end.