1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 5 const int N=100005; 6 int k,n,a[N]; 7 int partition(int begin,int end){ 8 while(begin<end){ 9 while(begin<end&&a[begin]>=a[end])end--; 10 if(begin<end){ 11 swap(a[begin],a[end]); 12 begin++; 13 } 14 while(begin<end&&a[begin]>=a[end])begin++; 15 if(begin<end){ 16 swap(a[begin],a[end]); 17 end--; 18 } 19 } 20 return end; 21 } 22 void quickSort(int begin,int end){ 23 int benchmark=partition(begin,end); 24 if(benchmark-1>begin)quickSort(begin,benchmark-1); 25 if(benchmark<k&&end>benchmark+1)quickSort(benchmark+1,end); 26 } 27 int main(){ 28 cin>>n; 29 for(int i=1;i<=n;i++) 30 scanf("%d",&a[i]); 31 cin>>k; 32 quickSort(1,n); 33 for(int i=1;i<=k;i++) 34 printf("%d\n",a[i]); 35 return 0; 36 }