Happy_Orca @ 2022-07-01 14:30:02
离谱,都是T后两个点的,我前两个点T了,后面都AC的
#include<bits/stdc++.h>
using namespace std;
int n,k,a[5000005];
inline int read(){
int ret=0;char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();
return ret;
}
void qsort(int x,int y){
int L=x,R=y,mid=a[(R+L)>>1];
while(L<R){
while(a[L]<mid&&L<R) L++;
while(a[R]>mid&&R>L) R--;
swap(a[L],a[R]);
}
if(R<k) qsort(R,y);
else if(R>k) qsort(x,R);
else{printf("%d\n",a[k]);return;}
}
int main(){
n=read(),k=read()+1;
for(int i=1;i<=n;i++) a[i]=read();
qsort(1,n);
return 0;
}