Shadow97 @ 2025-01-04 18:30:40
#include <bits/stdc++.h>
using namespace std;
int n,k,a[5000005];
int main ()
{
cin>>n>>k;
for (int i=0;i<n;i++)
cin>>a[i];
sort (a,a+n);
cout<<a[k]<<endl;
return 0;
}
by wangshengchen @ 2025-01-04 18:48:13
需要加速
#include<bits/stdc++.h>
using namespace std;
int n,m,a[5000000+10];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);//加快速度
cin>>n>>m;
m=m+1;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
cout<<a[m];
return 0;
}
@Shadow97
by Shadow97 @ 2025-01-04 20:51:23
@wangshengchen
ios::sync_with_stdio(false);
cin.tie(0);
```好了。不过这是怎么用的。。。
by wangshengchen @ 2025-01-04 21:48:44
@Shadow97 放main函数前两行(作用:使cin和scanf的输入速度一样,但不能混用了)
by craftmine @ 2025-01-05 09:38:25
@wangshengchen这样cin比scanf还快两倍,亲测
by Shadow97 @ 2025-01-05 20:36:39
@wangshengchen@craftmine。。。。耶??
by wangshengchen @ 2025-01-05 20:37:25
@Shadow97???