Zhangyanlin @ 2022-11-11 20:17:15
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,k;
cin>>m>>k;
int a[m+1];
for(int i=0;i<m;i++){
cin>>a[i];
}
sort(a,a+m);
cout<<a[k]<<endl;
return 0;
}
by Zhangyanlin @ 2022-11-11 20:39:11
问题已解决,用scanf和printf+O2优化就行了
by Zhangyanlin @ 2022-11-12 14:57:52
AC程序如下(记得开O2)
#include<bits/stdc++.h>
using namespace std;
int m,k;
int a[5000000];
int main(){
scanf("%d%d",&m,&k);
for(int i=0;i<m;i++){
scanf("%d",&a[i]);
}
sort(a,a+m);
printf("%d",a[k]);
return 0;
}
by Chesapeake_Ripper @ 2022-11-16 15:20:57
666666666
by Chesapeake_Ripper @ 2022-11-16 15:21:32
如果用冒泡排序就一定超时是吗?
by Zhangyanlin @ 2022-11-29 21:13:17
@Breath_the_shy 是的
这题只有1.00s,冒泡的时间复杂度太高,建议用分治或sort或桶排