Pagini recente » Cod sursa (job #2238262) | Cod sursa (job #158843)
Cod sursa(job #158843)
Program cel;
Type vector=array[1..1000] of longint;
var f,g:text;
suma,x:vector;
n,m,i,j,k,s,ic,sf,mij:longint;
ok:boolean;
procedure sortare(var x:vector;n:longint);
var min,t:longint;
Begin
For i:=1 to n-1 do
Begin
min:=x[i];
t:=i;
For j:=i+1 to n do
If min>x[j] then Begin
t:=j;
min:=x[j];
end;
If t<>i then Begin
x[t]:=x[i];
x[i]:=min;
end;
end;
end;
procedure afisare(p:longint);
var i,j,k,e:longint;
Begin
e:=0;
For i:=1 to n do
For j:=1 to n do
For k:=1 to n do
If (x[i]+x[j]+x[k]=suma[p]) and (e=0) then Begin
Write(g,i,' ',j,' ',k,' ');
inc(e);
end;
end;
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,x[i]);
m:=0;
For i:=1 to n do
For j:=1 to n do
For k:=1 to n do
Begin
m:=m+1;
suma[m]:=x[i]+x[j]+x[k];
end;
Sortare(suma,m);
ok:=false;
ic:=1;
sf:=m;
While ic<=sf do
Begin
mij:=(ic+sf) div 2;
If suma[i]+suma[mij]=S then Begin
ok:=true;
afisare(i);
afisare(mij);
i:=m+1;
end
else If suma[i]+suma[mij]>S then sf:=mij-1
else ic:=mij+1;
end;
If not ok then Write(g,-1);
Close(f);
Close(g);
end.