_Ayanami_Rei_ @ 2022-01-18 11:31:58
#include<iostream>
using namespace std;
int a[5000003];
int n,k,ans;
void qsort(int l,int r){
if(l==r){
ans=a[l];
return ;
}
int i=l,j=r,flag=a[(i+j)/2];
do{
while(a[i]<flag) ++i;
while(a[j]>flag) --j;
if(i<=j){
int tmp=a[i];
a[i]=a[j];
a[j]=tmp;
++i;
--j;
}
}while(i<=j);
if(j>=k) qsort(l,j);
else if(i<=k) qsort(i,r);
else qsort(j+1,i-1);
}
int main(){
cin>>n>>k;
for(int i=0;i<=n-1;++i){
cin>>a[i];
}
qsort(0,n-1);
cout<<ans<<" ";
return 0;
}
by william_zy @ 2022-02-14 22:53:22
把第1个return
改成cout<<ans<<" ";exit(0);
试试
by xiaoyaohanzi @ 2022-03-08 01:27:58
我开始最后一个也超时了,后来输入数组用了scanf就没事了