#include #include using namespace std; using ll = long long; using vll = vector; struct DynamicPriorityQueue{ priority_queue small;// small.top() は small の最大値 (K個になるようにする) priority_queue, greater> large; // large.top() は large の最小値 int K; void addElement(ll value) { if (small.size() < K) small.push(value); else { ll current_kth = small.top(); if (value < current_kth) { small.pop(); small.push(value); large.push(current_kth); } else { large.push(value); } } } ll getKthSmallest() { if (small.size() < K) { return -1; // K番目の値が存在しない場合は-1を返す } ll current_kth = small.top(); return current_kth; } void removeKthSmallest() { if (small.size() < K) return; // K番目の値が存在しない場合は何もしない ll current_kth = small.top(); small.pop(); if (!large.empty()) { long long next_kth = large.top(); large.pop(); small.push(next_kth); } } }; int main() { DynamicPriorityQueue dq; int Q, K; cin >> Q >> K; dq.K = K; vll ans; for (int i = 0; i < Q; ++i) { int T; cin >> T; if (T == 1) { ll V; cin >> V; dq.addElement(V); } else { ll kthSmallest = dq.getKthSmallest(); ans.push_back(kthSmallest); dq.removeKthSmallest(); } } for (int i = 0; i < ans.size(); ++i) { cout << ans[i] << endl; } return 0; }