#include #include using namespace std; template struct KQue { priority_queue max_q; priority_queue, greater> min_q; size_t K; KQue(size_t k): K(k) {} void push(T v) { if (max_q.size() < K) { max_q.push(v); return; } T ma_v = max_q.top(); if (ma_v > v) { max_q.pop(); max_q.push(v); min_q.push(ma_v); } else { min_q.push(v); } } T get() { if (max_q.size() < K) return -1; T ma_v = max_q.top(); max_q.pop(); if (min_q.size() != 0) { T mi_v = min_q.top(); min_q.pop(); max_q.push(mi_v); } return ma_v; } }; int main() { int Q, K; scanf("%d%d", &Q, &K); KQue kque(K); for(int i = 0; i < Q; i++) { int q; scanf("%d", &q); if (q == 1) { long long int v; scanf("%lld", &v); kque.push(v); } else { printf("%lld\n", kque.get()); } } return 0; }