Pagini recente » Cod sursa (job #676446) | Cod sursa (job #176516) | Cod sursa (job #2217246) | Cod sursa (job #1048931) | Cod sursa (job #47749)
Cod sursa(job #47749)
program loto;
var f,g:text;
s:array[1..100] of longint;
v:array[1..1000001] of longint;
poz:array[0..1000001] of longint;
n,sum,lv:longint;
procedure iofile;
var i,j,k:longint;
begin
assign(f,'loto.in');
reset(f);
assign(g,'loto.out');
rewrite(g);
readln(f,n,sum);
for i:=1 to n do
read(f,s[i]);
lv:=0;
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
begin
inc(lv);
v[lv]:=s[i]+s[j]+s[k];
poz[lv]:=lv;
end;
close(f);
end;
procedure pozitie(var m:longint;p,u:longint);
var i,j,di,dj,aux:longint;
begin
i:=p;
j:=u;
di:=0;
dj:=-1;
while i<j do
begin
if v[i]>v[j] then
begin
aux:=di;
di:=-dj;
dj:=-aux;
aux:=v[i];
v[i]:=v[j];
v[j]:=aux;
aux:=poz[i];
poz[i]:=poz[j];
poz[j]:=aux;
end;
i:=i+di;
j:=j+dj;
end;
m:=i;
end;
procedure quick(p,u:longint);
var m:longint;
begin
if p<u then
begin
pozitie(m,p,u);
quick(p,m-1);
quick(m+1,u);
end;
end;
function cbin(p,u,x:longint):byte;
var m:longint;
begin
if p>u then
cbin:=0 else
begin
m:=(p+u) div 2;
if v[m]=x then cbin:=m else
if v[m]<x then cbin:=cbin(m+1,u,x) else
if v[m]>x then cbin:=cbin(p,m-1,x);
end;
end;
procedure afis(s1,s2:longint);
var a:array[1..6] of longint;
aux,i,j,vl1,vl2:longint;
begin
a[1]:=s1 mod n;
if a[1]=0 then a[1]:=n;
a[2]:=s2 mod n;
if a[2]=0 then a[2]:=n;
vl1:=s1 mod (n*n);
if vl1=0 then vl1:=n*n;
vl2:=s2 mod (n*n);
if vl2=0 then vl2:=n*n;
a[3]:=vl1 div n+1;
if vl1 mod n=0 then dec(a[3]);
a[4]:=vl2 div n+1;
if vl2 mod n=0 then dec(a[4]);
n:=n*n;
a[5]:=s1 div n+1;
if s1 mod n=0 then dec(a[5]);
a[6]:=s2 div n+1;
if s2 mod n=0 then dec(a[6]);
for i:=1 to 5 do
for j:=i+1 to 6 do
if a[i]>a[j] then
begin
aux:=a[i];
a[i]:=a[j];
a[j]:=aux;
end;
for i:=1 to 6 do
write(g,a[i],' ');
close(g);
halt;
end;
procedure prel;
var i:longint;
begin
quick(1,lv);
for i:=1 to lv do
begin
if v[i]>sum div 2 then break;
if cbin(i+1,lv,sum-v[i])<>0 then
afis(poz[i],poz[cbin(i+1,lv,sum-v[i])]);
end;
writeln(g,'-1');
close(g);
end;
begin
iofile;
prel;
end.