7 3 7 2 5 3 1 6 4
3
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$idx=0; $n=intval($tokens[$idx++] ?? 0);
$k=intval($tokens[$idx++] ?? 1)-1;
$a=[];
for($i=0;$i<$n;$i++) $a[] = intval($tokens[$idx++] ?? 0);
$lo=0; $hi=$n-1;
while(true){
$pivot=$a[intdiv($lo+$hi,2)];
$i=$lo; $j=$hi;
while($i<=$j){
while($a[$i]<$pivot) $i++;
while($a[$j]>$pivot) $j--;
if($i<=$j){ $t=$a[$i]; $a[$i]=$a[$j]; $a[$j]=$t; $i++; $j--; }
}
if($k<=$j) $hi=$j;
elseif($k>=$i) $lo=$i;
else{ echo $a[$k]; break; }
}
?>
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$idx=0; $n=intval($tokens[$idx++] ?? 0);
$k=intval($tokens[$idx++] ?? 1)-1;
$a=[];
for($i=0;$i<$n;$i++) $a[] = intval($tokens[$idx++] ?? 0);
$lo=0; $hi=$n-1;
while(true){
$pivot=$a[intdiv($lo+$hi,2)];
$i=$lo; $j=$hi;
while($i<=$j){
while($a[$i]<$pivot) $i++;
while($a[$j]>$pivot) $j--;
if($i<=$j){ $t=$a[$i]; $a[$i]=$a[$j]; $a[$j]=$t; $i++; $j--; }
}
if($k<=$j) $hi=$j;
elseif($k>=$i) $lo=$i;
else{ echo $a[$k]; break; }
}
?>