Pagini recente » Cod sursa (job #3245637) | Cod sursa (job #209037) | Cod sursa (job #2553760) | Cod sursa (job #990720) | Cod sursa (job #872493)
Cod sursa(job #872493)
program loto;
var d : array[0..6] of byte;
a : array[0..100] of longint;
f,g : text;
s,r,min,max : longint;
i,n,k : byte;
ok : boolean;
begin
assign(f,'loto.in'); reset(f);
assign(g,'loto.out'); rewrite(g);
readln(f,n,s);
for i := 1 to n do read(f,a[i]);
min := a[1]; max := min;
for i := 1 to n do
if a[i] > max then max := a[i]
else if a[i] < min then min := a[i];
ok := true;
if (min*6 <= s) and (max*6 >= s) then begin
k := 1; d[k] := 0;
while k > 0 do begin
while d[k] < n do begin
inc(d[k]); r := r - a[d[k-1]] + a[d[k]];
if r <= s then
if k = 6 then begin
if s = r then begin
for i := 1 to 6 do write(g,a[d[i]],' ');
ok := false;
end;
end
else begin
inc(k);
d[k] := 0;
end;
end;
dec(k);
end;
end;
if ok then write(g,-1);
close(f); close(g);
end.