提交时间:2023-11-16 20:53:38

运行 ID: 31127

#include <bits/stdc++.h> using namespace std; int n,k,a[100010]; void qs(int a[],int left,int right){ int i=left,j=right; int mid=a[(left+right)/2]; while(i<=j){ while(a[i]>mid)i++; while(a[j]<mid)j--; if(i<=j){ int tmp=a[i]; a[i]=a[j]; a[j]=tmp; i++,j--; } } if(left<j)qs(a,left,j); if(i<right)qs(a,i,right); } int mian(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } cin>>k; qs(a,1,n); for(int i=1;i<=k;i++){ cout<<a[i]<<endl; } return 0; }