ResonCaolol @ 2023-01-04 12:31:29
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
int a[100860000];
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
cout<<a[k];
return 0;
}
by Kirisamex @ 2023-01-04 12:34:30
普通快排过不了。建议手动实现+二分优化
by wangweichen666 @ 2023-01-04 12:45:23
建议用分治,实在不行用nth_element
by tbdsh @ 2023-01-04 13:14:53
@crc666
加个快读就过了,或者用 scanf
和 printf
也能过
by tbdsh @ 2023-01-04 13:15:36
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, sum[5000005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);//关闭同步流,加快速度
cin >> m >> n;
for (int i = 1; i <= m; i++){
cin >> sum[i];
}
sort(sum + 1, sum + m + 1);
cout << sum[n + 1];
return 0;
}
by ResonCaolol @ 2023-01-04 13:19:41
@tianbiandeshenghuo11 scanf 和 printf也是T
by InversionShadow @ 2023-01-04 13:47:56
@tianbiandeshenghuo11 耍小聪明