#include #include #include #include using namespace std; template using max_heap = priority_queue; template using min_heap = priority_queue, greater>; int main() { // 1, 2, ..., K, K + 1, ... // └─ small ─┘ └─ large ─┘ max_heap small; min_heap large; int q, k; cin >> q >> k; while (q--) { int t; cin >> t; if (t == 1) { long long v; cin >> v; if (small.size() < k) { small.emplace(v); continue; } long long kth = small.top(); if (v < kth) { small.pop(); small.emplace(v); large.emplace(kth); } else { large.emplace(v); } } else { if (small.size() < k) { cout << -1 << endl; continue; } long long kth = small.top(); small.pop(); cout << kth << endl; if (!large.empty()) { kth = large.top(); large.pop(); small.emplace(kth); } } } return 0; }