#include #include #include using namespace std; using ll = long long; using vll = vector; struct DynamicMultiset { multiset small; // smallは昇順で要素を保持するmultiset multiset large; // largeは昇順で要素を保持するmultiset int K; // k番目に小さい値の管理数 void add(ll value) { if (small.size() < K) { small.insert(value); } else { ll current_kth = *(--small.end()); if (value < current_kth) { small.erase(--small.end()); small.insert(value); large.insert(current_kth); } else { large.insert(value); } } } ll getKthSmallest() { if (small.size() < K) { return -1; } return *(--small.end()); } void remove() { if (small.size() < K) { return; } ll current_kth = *(--small.end()); small.erase(--small.end()); if (!large.empty()) { ll next_kth = *large.begin(); large.erase(large.begin()); small.insert(next_kth); } } }; using ll = long long; using vll = vector; int main() { DynamicMultiset dm; int Q, K; cin >> Q >> K; dm.K = K; vll ans; for (int i = 0; i < Q; ++i) { int T; cin >> T; if (T == 1) { ll V; cin >> V; dm.add(V); } else { ll kthSmallest = dm.getKthSmallest(); ans.push_back(kthSmallest); dm.remove(); } } for (int i = 0; i < ans.size(); ++i) { cout << ans[i] << endl; } return 0; }