#include<iostream>#include<vector>#define lowbit(x) ((x) & (-x))usingnamespace std;constint N =1025;int c[N]={0};voidadd(int x,int v){for(int i = x; i < N; i +=lowbit(i)) c[i]+= v;}intgetSum(int x){if(x <1)return0;elsereturn c[x]+getSum(x -lowbit(x));}intgetKthLeast(int k){int left =1, right = N -1, mid;while(left < right){
mid =(left + right)/2;if(getSum(mid)>= k) right = mid;else left = mid +1;}return left;}intmain(){int n, k, temp, cnt =0;while(true){while(cin >> temp, temp !=-1){add(temp,1);}printf("Input the k to search: ");scanf("%d",&k);if(k !=-1){printf("The k-th least number is %d\n",getKthLeast(k));break;}elsecontinue;}return0;}