Cod sursa(job #171421)

Utilizator mariusake212Isac Marius-Sergiu mariusake212 Data 4 aprilie 2008 12:23:00
Problema Loto Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.81 kb
var
   g:text;
   v:array[1..100]of longint;
   n,a,b,c,d,e,f,i,max:integer;
   s,st:longint;
begin
     assign(g,'loto.in');reset(g);
     read(g,n,s);
     max:=0;
     for i:=1 to n do
         begin
         read(g,v[i]);
         if max<v[i]then max:=v[i];
         end;
     close(g);assign(g,'loto.out');rewrite(g);
     if s>(6*max) then begin write(g,-1);close(g); exit; end
                 else
                          for a:=1 to n do
                              for b:=a to n do
                                  for c:=b to n do
                                      for d:=c to n do
                                          for e:=d to n do
                                              for f:=e to n do
                                                  begin
                                                  st:=v[a]+v[b]+v[c]+v[d]+v[e]+v[f];
                                                  if st=s then
                                                           begin
                                                          write(g,v[a],' ',v[b],' ',v[c],' ',v[d],' ',v[e],' ',v[f]);
                                                          close(g);
                                                           exit;
                                                           end
                                                           else if st>s then
                                                                   begin
                                                                   write(g,-1);
                                                                   close(g);
                                                                   exit
                                                                   end;
                                                   end

end.