Cod sursa(job #26155)

Utilizator raduzerRadu Zernoveanu raduzer Data 5 martie 2007 11:53:49
Problema Loto Scor 5
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.68 kb
var a:array[1..100]of longint;
    n,i,j,s,x,l,k,o,p,q:longint;


procedure Sort(l, r: Integer);
var
  i, j, x, y: integer;
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,'loto.in');
     reset(input);
     assign(output,'loto.out');
     rewrite(output);
     readln(n,s);
     for i:=1 to n do read(a[i]);
     sort(1,n);
     q:=0;
     for i:=1 to n do
     begin
          for j:=i to n do
          begin
               for l:=j to n do
               begin
                    for k:=l to n do
                    begin
                         for o:=k to n do
                         begin
                              for p:=o to n do
                              begin
                                   if a[i]+a[j]+a[l]+a[k]+a[o]+a[p]=s then
                                   begin
                                        q:=1;
                                        writeln(a[i],' ',a[j],' ',a[l],' ',a[k],' ',a[o],' ',a[p]);
                                   end;
                              end;
                              if q=1 then break;
                         end;
                         if q=1 then break;
                    end;
                    if q=1 then break;
               end;
               if q=1 then break;
          end;
          if q=1 then break;
     end;
     if q=0 then writeln(-1);
close(output);
end.