Anzhitinglan @ 2023-09-25 22:33:42
#include<iostream>
#include<stdio.h>
using namespace std;
int n , k , ans , a[50000000];
void qsort(int a[], int l ,int r)
{
//if(l == r) return ;
if(l == r)
{
//ans = a[l];
return ;
}
int i = l , j = r , tmp , flag = a[( l + r ) / 2] ;
do{
while(a[i] < flag) i++;
while(a[j] > flag) j--;
if(i <= j)
{
tmp = a[i];
a[i] = a[j] ;
a[j] = tmp ;
i++;j--;
}
}while(i<=j);
if(k <= j) qsort(a, l, j) ;
else if(k >= i) qsort(a, i, r);
else qsort(a, j+1, i-1) ;
//if(l < j) qsort(l, j);
//if(i < r) qsort(i, r);
}
int main()
{
//int a[500000000];
cin >> n >> k;
for(int i = 1 ; i <= n ; i++ ) cin >> a[i] ;
qsort(a, 1 , n) ;
//for(int i = 1 ; i <= n ; i++) cout << a[i] << ' ';
cout << a[k+1] ;
return 0;
}
by xibaohe @ 2023-09-25 22:49:53
ios优化或者换用scanf/printf
by ZackofZHOU @ 2023-09-30 21:07:57
else
后面好像是直接输出