K_func @ 2024-01-29 10:44:30
#include <bits/stdc++.h>
using namespace std;
int n,k,arr[5000001];
int read(){
int x=0,f=1;
char c=getchar();
while(c>='0' && c<='9')
x=x*10+c-'0',c=getchar();
return x*f;
}
int main(){
n = read();
k = read();
for(int i=1;i<=n;i++){
arr[i] = read();
}
sort(arr,arr+n);
cout<<arr[k+1];
return 0;
}
by K_func @ 2024-01-29 10:45:59
打错了,应该是
#3 #5 WA #1,#2,#4 AC
by Walrus @ 2024-01-29 10:48:19
@Jadejunxi 可以去看看 sort
的排序规则,你既然数组从 1 起就应该像我这样排,如果
#include <bits/stdc++.h>
using namespace std;
int n,k,arr[5000001];
int read(){
int x=0,f=1;
char c=getchar();
while(c>='0' && c<='9')
x=x*10+c-'0',c=getchar();
return x*f;
}
int main(){
n = read();
k = read();
for(int i=1;i<=n;i++){
arr[i] = read();
}
sort(arr+1,arr+n+1);
cout<<arr[k];
return 0;
}
by K_func @ 2024-01-29 10:49:12
@woshifujiarui OK,已关
by Walrus @ 2024-01-29 10:50:34
@Jadejunxi 而且这个题貌似要去重,不能直接排序。