Cod sursa(job #301948)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 8 aprilie 2009 15:54:08
Problema Loto Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.26 kb
program alex;
var f:text;
    a:array[1..150]of longint;
    st:array[1..10]of integer;
    e,as:boolean;
    i,n,k,j,s:longint;
begin
assign(f,'loto.in');reset(f);
readln(f,n,k);
for i:=1 to n do
    read(f,a[i]);
close(f);
j:=1;
st[j]:=0;
s:=0;
e:=false;
assign(f,'loto.out');rewrite(f);
while(j>0)and(e=false)do
      begin
      if st[j]<n then begin
                      s:=s-a[st[j]];
                      st[j]:=st[j]+1;
                      as:=true;
                      s:=s+a[st[j]];
                      end
                 else as:=false;
      if as then begin
                 if j=6 then begin
                             if s=k then begin
                                         e:=true;
                                         for i:=1 to j do
                                             write(f,a[st[i]],' ');
                                         end;
                             end
                        else begin
                             j:=j+1;
                             st[j]:=0;
                             end;
                 end
            else begin
                 s:=s-a[st[j]];
                 j:=j-1;
                 end;
      end;
if e=false then writeln(f,-1);
close(f);
end.