mezWindows @ 2021-07-29 17:07:20
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
long long c[5000007];
int main(){
int a,b;
cin>>a>>b;
for(int i=0;i<a;i++){
cin>>c[i];
}
sort(c,c+a);
cout<<c[b];
return 0;
}
by ClapEcho233 @ 2021-07-29 17:13:24
你用sort肯定T啊
by mezWindows @ 2021-07-29 17:14:37
难道要用nth_element??????????????????????????????????????????????????
by ClapEcho233 @ 2021-07-29 17:15:56
题解内有详细说明
by mezWindows @ 2021-07-29 17:16:35
膜拜大佬 Orz Orz
by mezWindows @ 2021-07-29 17:17:08
我还是用
nth_element吧
by mezWindows @ 2021-07-29 17:18:33
WOC,nth也TLE!!!
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
long long c[5000007];
int main(){
int a,b;
cin>>a>>b;
for(int i=0;i<a;i++){
cin>>c[i];
}
nth_element(c,c+b,c+a);
cout<<c[b];
return 0;
}
不想用快排
by Kanbe_Kotori @ 2021-07-29 17:20:53
建议百度时间复杂度
by 我送送送送 @ 2021-07-29 17:26:11
把cin
改成scanf
by 我送送送送 @ 2021-07-29 17:27:01
或者加上ios::sync_with_stdio(false)
by ud2_ @ 2021-07-29 17:28:33
卡常题。加点优化(任何优化)就能过了。
推荐的做法是 std::ios_base::sync_with_stdio(false)
。