Pagini recente » Cod sursa (job #1010418) | Cod sursa (job #1851159) | Cod sursa (job #1441611) | Cod sursa (job #1840181) | Cod sursa (job #913111)
Cod sursa(job #913111)
var f,g:text;n,x,i,z:integer;v:array[1..3000000]of integer;
procedure Quicksort(Left, Right: integer);
var
ptrLeft, ptrRight, Pivot, Temp: integer;
begin
ptrLeft := Left;
ptrRight := Right;
Pivot :=v[z]; {v[(Left + Right) div 2];}
repeat
while (ptrLeft < Right) and (v[ptrLeft] < Pivot) do
inc(ptrLeft);
while (ptrRight > Left) and (v[ptrRight] > Pivot) do
dec(ptrRight);
if ptrLeft <= ptrRight then
begin
if ptrLeft < ptrRight then
begin
Temp := v[ptrLeft];
v[ptrLeft] := v[ptrRight];
v[ptrRight] := Temp;
end;
inc(ptrLeft);
dec(ptrRight);
end;
until ptrLeft > ptrRight;
if ptrRight > Left then
Quicksort(Left, ptrRight);
if ptrLeft < Right then
Quicksort(ptrLeft, Right);
end;
begin
assign(f,'sdo.in');reset(f);
assign(g,'sdo.out');rewrite(g);
readln(f,n,x);z:=x;
for i:=1 to n do
read(f,v[i]);
quicksort(1,n);
write(g,v[x]);
for i:=1 to n do
write(v[i]:3);
close(f);
close(g);
end.