Pagini recente » Cod sursa (job #79738) | Rating asdfgh (abcdefg123) | Cod sursa (job #698554) | Cod sursa (job #1799093) | Cod sursa (job #913344)
Cod sursa(job #913344)
var f,g:text
;n,x,i,aux:longint;
v:array[1..3000000]of longint;
procedure Quicksort(Left, Right: longint);
var
ptrLeft, ptrRight, Pivot, Temp: longint;
begin
ptrLeft := Left;
ptrRight := Right;
Pivot :=v[x]; {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 v[x]<>aux then begin
if ptrRight > Left then
Quicksort(Left, ptrRight);
if ptrLeft < Right then
Quicksort(ptrLeft, Right);aux:=v[x];end;
end;
begin
assign(f,'sdo.in');reset(f);
assign(g,'sdo.out');rewrite(g);
readln(f,n,x);
for i:=1 to n do
read(f,v[i]);
quicksort(1,n);
write(g,v[x]);
close(f);
close(g);
end.