Cod sursa(job #188312)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 7 mai 2008 20:43:32
Problema Economie Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.08 kb
var a: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]);
        val[a[i]]:=1;
        end;
sort(1,n);

for i:=1 to n do
        begin
        if val[a[i]]=1 then
        for j:=1 to a[n] -a[i] do
             if val[j]<>0 then
                             val[j+a[i]]:=2;
        end;
k:=0;
for i:=1 to n do
        if val[a[i]]=1 then begin
                                inc(K);
                                a[k]:=a[i];
        end;
writeln(K);
for i:=1 to k do writeln(a[i]);
close(input);
close(output);
end.