Pagini recente » Cod sursa (job #382132) | Cod sursa (job #1585282) | Cod sursa (job #1390235) | Cod sursa (job #115971) | Cod sursa (job #27909)
Cod sursa(job #27909)
Program loto;
var f,g:text;
a:array[1..100] of real;
N,i:byte;
s,sc:real;
st:array[1..6] of real;
gata:boolean;
Procedure intercl(st,mid,fin:integer);
var b:array[1..100] of real; i,j,k:byte;
begin
for i:=st to fin do b[i]:=0;
i:=st;k:=st;j:=mid+1;
while (i<=mid) and (j<=fin) do
if a[i]<a[j] then begin b[k]:=a[i]; i:=i+1; k:=k+1; end
else begin b[k]:=a[j]; j:=j+1; k:=k+1;end;
if i<=mid then for j:=i to mid do begin b[k]:=a[j];k:=k+1; end
else for i:=j to fin do begin b[k]:=a[i];k:=k+1; end;
for i:=st to fin do begin a[i]:=b[i]; end;
end;
procedure mergesrt(st,fin:integer);
var c:integer;
begin
if st<fin then
begin
c:=(st+fin) div 2;
mergesrt(st,c);
mergesrt(c+1,fin);
intercl(st,c,fin);
end;
end;
Function max:byte;
var j:byte;
begin
if s-sc>a[n div 2] then
begin max:=n;
for j:= n downto 1 do
if s-sc<=a[j] then begin max:=j; break; end;
end
else begin max:=1;
for j:=1 to n do
if s-sc<=a[j] then begin max:=j;
break; end;
end;
end;
Procedure bktr(p:byte);
var pval:byte;
begin
if s-sc>a[1] then
for pval:=1 to max do
begin
st[p]:=a[pval];
sc:=sc+st[p];
if p=6 then begin
if sc=s then begin
gata:=true;
for i:=1 to 6 do write(g,st[i]:0:0,' ');
end
end
else if not gata then bktr(p+1);
if gata then break;
sc:=sc-st[p];
end;
end;
begin
assign(f,'loto.in'); reset(f);
assign(g,'loto.out'); rewrite(g);
readln(f,n,s);
for i:=1 to 6 do st[i]:=0;
for i:=1 to n do read(f,a[i]);
gata:=false;
mergesrt(1,n);
sc:=0;
bktr(1);
if not gata then writeln(g,-1);
close(g);
close(f);
end.