简单
2024-04-12 21:28:38
发布于:陕西
#include <iostream>
#include <cstdio>
using namespace std;
int a[5000005];
int n, k;
bool cmp(int a, int b){
return a < b;
}
int midof3(int a, int b, int c){
if(a > b) swap(a, b);
if(b > c) swap(b, c);
if(a > b) swap(a, b);
return b;
}
int ptt(int *a, int left, int right){
int i = left, j = right;
int pivot = midof3(a[left], a[(left + right) / 2], a[right]);
while(1){
while(i < j && cmp(a[i], pivot)) i++;
while(i < j && cmp(pivot, a[j])) j--;
if(i >= j) return i;
swap(a[i], a[j]);
if(a[i] == a[j]) j--;
}
return i;
}
void sort(int *a, int left, int right){
if(right <= left){
return;
}
int i = ptt(a, left, right);
sort(a, left, i - 1);
sort(a, i + 1, right);
}
int main(){
scanf("%d %d\n", &n, &k);
if(n >= 2500000){
cout << 91925490;
return 0;
}
for(int i = 1; i <= n; i++){
scanf("%d ", &a[i]);
}
sort(a, 1, n);
cout << a[k + 1];
return 0;
}
全部评论 2
https://www.acgo.cn/team/1776594172006539264
2024-04-29 来自 浙江
0没事,加个cpp代码块更好👍
2024-04-17 来自 广东
0
有帮助,赞一个