#include #include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; const int log = 31; struct BinaryTrie { struct Node { int par, cnt, b0, b1; }; vector arr; explicit BinaryTrie(void) { arr.push_back(Node{-1, 0, -1, -1}); } inline int __append(int p, int nxt_bit) { int idx = arr.size(); arr.push_back({p, 0, -1, -1}); if(nxt_bit == 0) arr[p].b0 = idx; if(nxt_bit == 1) arr[p].b1 = idx; return idx; } inline int move(int p, int nxt_bit) { if(nxt_bit == 0) { if(arr[p].b0 == -1) return __append(p, nxt_bit); else return arr[p].b0; } else { if(arr[p].b1 == -1) return __append(p, nxt_bit); else return arr[p].b1; } } void add_value(int x) { int root = 0; for(int i = log; i >= 0; i--) { root = move(root, (x>>i)&1); } while(root >= 0) { arr[root].cnt++; root = arr[root].par; } } inline int subtree_cnt(int r) { if(r == -1) return 0; return arr[r].cnt; } int lower_bound(int value, int x=0) { int lb = 0; int root = 0; for(int i = log; i >= 0; i--) { int nxt_bit = (value>>i)&1; int flip = (x>>i)&1; if(nxt_bit == 1) { if(flip) lb += subtree_cnt(arr[root].b1); else lb += subtree_cnt(arr[root].b0); } root = move(root, nxt_bit^flip); } return lb; } int upper_bound(int value, int x=0) { int ub = 0; int root = 0; for(int i = log; i >= 0; i--) { int nxt_bit = (value>>i)&1; int flip = (x>>i)&1; if(nxt_bit) { if(flip) ub += subtree_cnt(arr[root].b1); else ub += subtree_cnt(arr[root].b0); } root = move(root, nxt_bit^flip); } ub += subtree_cnt(root); return ub; } }; int main() { BinaryTrie bt; long long n, k; cin >> n >> k; vector a(n); for(int i = 0; i < n; ++i) { cin >> a[i]; bt.add_value(a[i]); } // Find N + 2 * K kth number const long long pos = n + 2 * k - 1; int ng = -1, ok = 1e9; while(ok - ng > 1) { int x = (ok + ng) >> 1; long long count = 0; for(int i = 0; i < n; ++i) { count += bt.upper_bound(x, a[i]); } if(count >= pos) ok = x; else ng = x; } cout << ok << endl; }