Pagini recente » Cod sursa (job #1240984) | Cod sursa (job #356680) | Ciorna | Cod sursa (job #400943) | Cod sursa (job #188317)
Cod sursa(job #188317)
var a,b:array[1..1000] of word;
val:array[1..50000] of byte;
n,i,j,k:word;
procedure Sort(l, r: word);
var
i, j, x, y: word;
begin
i := l; j := r; x := a[(l+r) DIV 2];
repeat
while a[i] < x do i := i + 1;
while x < a[j] do j := j - 1;
if i <= j then
begin
y := a[i]; a[i] := a[j]; a[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j);
if i < r then Sort(i, r);
end;
begin
assign(input,'economie.in');
assign(output,'economie.out');
reset(input);
rewrite(output);
readln(N);
for i:=1 to n do
begin
read(a[i]);
end;
sort(1,n); k:=0;
fillchar(val,sizeof(val),0);
for i:=1 to n do
if val[a[i]]=0 then
begin
val[a[i]]:=1;
inc(K);
b[k]:=a[i];
for j:=a[i]+1 to a[n] do
if val[j-a[i]]<>0 then
val[j]:=2;
end;
writeln(K);
for i:=1 to k do writeln(b[i]);
close(input);
close(output);
end.