#include<iostream>
using namespace std;
void swap(int &i,int &j){
int temp=i;
i=j;
j=temp;
};
int kmax(int *A,int low,int high,int k){
if(k<=0){
cout<<"false argument"<<endl;
return -1;
}
int i=low;
int j=high+1;
int pivot=A[low];
while(true){
while(A[++i]<pivot){
if(i==high)
break;
}
while(A[--j]>pivot);
if(i>=j)
break;
swap(A[i],A[j]);
}
swap(A[low],A[j]);
if(high-j+1==k)
return A[j];
else if(high-j+1<k)
return kmax(A,low,j-1,k-high+j-1);
else
return kmax(A,j+1,high,k);
}
int main(){
int A[]={1,4,5,6,8,11,3};
cout<<kmax(A,0,6,5)<<endl;
}