Pagini recente » Cod sursa (job #2600892) | Cod sursa (job #1346107) | Cod sursa (job #1900925) | Rating Anda Totilca (andatotalca) | Cod sursa (job #910824)
Cod sursa(job #910824)
var f,g:text;n,x,i: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[(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);
for i:=1 to n do
read(f,v[i]);
quicksort(1,n);
write(g,v[x]);
close(f);
close(g);
end.