#define NODEBUG #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using llong = long long; //=== //#include template > struct FindKth { using Heap = priority_queue, Compare>; const int K; Heap maxh; Heap minh; FindKth (const int K, const Compare &cmp = less()): K(K), maxh(cmp), minh([&cmp](auto l, auto r){ return cmp(r, l); }) {}; size_t size() { return maxh.size() + minh.size(); }; bool empty() { return size() > 0 ? false : true; }; void push(T &d){ maxh.push(d); if (maxh.size() > K) { minh.push(maxh.top()); maxh.pop(); } }; T find(){ assert(maxh.size() == K); return maxh.top(); }; T find_lower(){ assert(!empty()); return maxh.top(); }; void pop() { assert(!empty()); maxh.pop(); if (!minh.empty()) { maxh.push(minh.top()); minh.pop(); } }; void merge_with(FindKth &r) { FindKth &l = *this; if (l.size() < r.size()) swap(l, r); while (!r.empty()){ l.push(r.find_lower()); r.pop(); } }; }; //=== int yc649() { llong q, k; llong com, v; cin >> q >> k; FindKth st(k); while (q--) { cin >> com; if (com == 1) { cin >> v; st.push(v); } else { if (st.size() < k) { cout << -1 << endl; } else { cout << st.find() << endl; st.pop(); } } } cout << endl; return 0; } int main() { return yc649(); }