Pagini recente » Cod sursa (job #1821474) | Cod sursa (job #678182) | Cod sursa (job #452198) | Cod sursa (job #2564776) | Cod sursa (job #51231)
Cod sursa(job #51231)
var f,g:text;
a:array[1..100] of longint;
st:array[1..6] of byte;
n,k,i:byte;
s,s1:longint;
as,ev,ok:boolean;
procedure init;
begin
st[k]:=0;
end;
procedure succesor;
begin
if st[k]<n then begin
as:=true;
st[k]:=st[k]+1;
end
else as:=false;
end;
procedure valid;
begin
ev:=true;
for i:=1 to k do if st[i]=0 then ev:=false;
end;
function solutie(k:integer):boolean;
begin
solutie:=k=6;
end;
procedure tipar;
begin
s1:=0;
for i:=1 to 6 do s1:=s1+a[st[i]];
if s1=s then begin
for i:=1 to 6 do write(g,a[st[i]],' ');
ok:=true;
end;
end;
begin
assign(f,'loto.in'); reset(f);
assign(g,'loto.out'); rewrite(g);
read(f,n,s);
for i:=1 to n do read(f,a[i]);
k:=1;
init;
ok:=false;
while k>0 do begin
repeat
succesor;
if as then valid;
until (not as) or (as and ev);
if as then if solutie(k) then begin
tipar;
if ok then break;
end
else begin
k:=k+1;
init;
end
else k:=k-1;
end;
if not ok then write(g,'-1');
close(g);
end.