Pagini recente » Cod sursa (job #228570) | Cowfood | Cod sursa (job #3219818) | Cod sursa (job #386769) | Cod sursa (job #17976)
Cod sursa(job #17976)
var a:array[1..128]of longint;
b:array[1..6]of longint;
n,s,i,j,z,x,q:longint;
procedure back(x:integer);
var i:integer;
begin
if (x=7)and(s=z) then
begin
for i:=1 to 6 do write(b[i],' ');
q:=1;
exit;
end;
if x=7 then exit;
for i:=1 to n do
begin
if q=1 then exit;
z:=z+a[i];
b[x]:=a[i];
back(x+1);
b[x]:=0;
z:=z-a[i];
end;
end;
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);
x:=1;
back(1);
if q=0 then writeln(-1);
close(output);
end.