_Patrick_Star_ @ 2025-01-11 17:50:05
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
print(c[b])
by be_the_person @ 2025-01-11 18:42:32
@_PatrickStar AC代码
#include<bits/stdc++.h>
using namespace std;
int q[5000005], k;
void qsort(int l, int r)
{
int i = l, j = r, x = q[(l + r) / 2];
do
{
while(q[j] > x) j -- ;
while(q[i] < x) i ++ ;
if(i <= j)
{
swap(q[i], q[j]);
i ++ , j -- ;
}
}while(i <= j);
if(k <= j) qsort(l, j);
else if(i <= k) qsort(i, r);
else
{
printf("%d\n", q[j + 1]);
exit(0);
}
}
int main()
{
int n;
scanf("%d%d",&n, &k);
for(int i = 0; i < n; i ++ ) scanf("%d", &q[i]);
qsort(0, n - 1);
}