Pagini recente » Cod sursa (job #2670351) | Cod sursa (job #3217859) | Cod sursa (job #2746782) | Cod sursa (job #2519472) | Cod sursa (job #56995)
Cod sursa(job #56995)
type vector=array[0..1001000]of longint;
var x,p1,p2,p3:vector;
i,j,k,n,s,g,sum,aux:longint;
v:array[1..1300]of longint;
procedure qsort(ls,ld:longint);
var i,j,aux:longint;
begin
i:=ls;j:=ld;
while true do begin
while (x[i]<=x[j])and(i<>j) do inc(i);
if i=j then break;
aux:=x[i];x[i]:=x[j];x[j]:=aux;dec(j);
while (x[i]<=x[j])and(i<>j) do dec(j);
if i=j then break;
aux:=x[i];x[i]:=x[j];x[j]:=aux;inc(i);
end;
if j-1>ls then qsort(ls,j-1);
if j+1<ld then qsort(j+1,ld);
end;
function gasit(n,ls,ld:longint):longint;
var m:longint;
begin
m:=(ls+ld) div 2;
if x[m]=n then
begin
gasit:=m;
exit;
end;
if ls>=ld then
begin
gasit:=0;
exit;
end;
if n<x[m] then
gasit:=gasit(n,ls,m-1)
else
gasit:=gasit(n,m+1,ld);
end;
begin
assign(input,'loto.in');reset(input);
assign(output,'loto.out');rewrite(output);
readln(n,s);
for i:=1 to n do
read(v[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if v[i]>v[j] then
begin
aux:=v[i];
v[i]:=v[j];
v[j]:=aux;
end;
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
begin
inc(x[0]);
x[x[0]]:=v[i]+v[j]+v[k];
p1[x[0]]:=i;
p2[x[0]]:=j;
p3[x[0]]:=k;
end;
qsort(1,x[0]);
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
begin
sum:=v[i]+v[j]+v[k];
sum:=s-sum;
if (sum>=0) then
begin
g:=gasit(sum,1,x[0]);
if g<>0 then
begin
writeln(v[i],' ',v[j],' ',v[k],' ',v[p1[g]],' ',v[p2[g]],' ',v[p3[g]]);
close(output);
halt;
end;
end;
end;
writeln(-1);
close(input);close(output);
end.