public int[] search(int[] a,  int k){
        if(a==null || k>a.length) return new int[0];
        int[]result=new int[k];
        int cur=-1;
        for(int i=0;i<k;++i){
            cur=max(a,cur,a.length-k+1+i);
            result[i]=a[cur];
        }
        return result;
    }