xjm2023 @ 2024-11-09 10:28:31
#include<iostream>
using namespace std;
int a[5000005];
int n,k;
int bsort(int l,int r){
int i=l,j;
for(int m=l+1;m<=r;m++){
if(a[l]>a[m]){
i++;
swap(a[m],a[i]);
}else if(a[l]<a[m]) swap(a[m],a[i+1]);
}
swap(a[l],a[i]);
if(k<i) bsort(0,i-1);
else if(k>i) bsort(i+1,r);
else return a[k];
}
int main(){
scanf("%d%d",n,k);
for(int i=0;i<n;i++){
scanf("%d",a[i]);
}
printf("%d",bsort(0,n-1));
return 0;
}