#include #include #include #include using namespace std; int main(){ int Q, K; cin >> Q >> K; priority_queue, less> K_left; long Kth = -1; priority_queue, greater> K_right; int array_size = 0; for(int i = 0; i < Q; i++){ int type; cin >> type; if(type == 1){ long num; cin >> num; array_size++; K_left.push(num); if(array_size == K){ Kth = K_left.top(); K_left.pop(); }else if(array_size > K){ K_right.push(Kth); K_right.push(K_left.top()); K_left.pop(); Kth = K_right.top(); K_right.pop(); } }else{ if(array_size < K){ cout << -1 << endl; }else{ array_size--; cout << Kth << endl; if(array_size >= K){ Kth = K_right.top(); K_right.pop(); }else{ Kth = -1; } } } } }