yang1812 @ 2023-11-15 13:49:20
#include<bits/stdc++.h>
using namespace std;
int n,k,a[250001],s;
int main(){
scanf("%d%d",&n,&k);
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n - i;i++){
if(a[j] > a[j + 1]){
sort(a[j] , a[j + 1]);
}
}
}
s = a[k];
printf("%d",s);
}
by 迟暮天复明 @ 2023-11-15 13:53:34
《sort(a[j],a[j+1])》
by zhaohanwen @ 2023-11-15 14:25:23
@yang1812 您是怎么理解 sort()
的。。。。
by zhaohanwen @ 2023-11-15 14:30:29
@yang1812 改成这个:
问题:数组开小,sort一遍就行了。
#include<bits/stdc++.h>
using namespace std;
int n,k,a[5000001],s;
int main(){
scanf("%d%d",&n,&k);
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
}
sort(a+1,a+1+n);
printf("%d",a[k+1]);
}
by yang1812 @ 2023-11-15 19:09:54
@zhaohanwen 后面两个测试点超时了!!
by zhaohanwen @ 2023-11-15 19:33:21
@yang1812 开