// yukicoder: 649 ここでちょっとQK // 2019.6.2 bal4u #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif long long in() // 非負整数の入力 { long long n = 0; int c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void out(long long n) // 非負整数の表示(出力) { int i; char b[40]; if (!n) pc('0'); else { i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } pc('\n'); } #define MAX 200005 long long que[2][MAX]; int qsize[2]; #define PARENT(i) ((i)>>1) #define LEFT(i) ((i)<<1) #define RIGHT(i) (((i)<<1)+1) void min_heapify(int id, int i) { int l, r, min; l = LEFT(i), r = RIGHT(i); if (l < qsize[id] && que[id][l] < que[id][i]) min = l; else min = i; if (r < qsize[id] && que[id][r] < que[id][min]) min = r; if (min != i) { long long t = que[id][i]; que[id][i] = que[id][min]; que[id][min] = t; min_heapify(id, min); } } void deq(int id) { que[id][0] = que[id][--qsize[id]]; min_heapify(id, 0); } void enq(int id, long long t) { int i, min; i = qsize[id]++; que[id][i] = t; while (i > 0 && que[id][min = PARENT(i)] > que[id][i]) { long long t = que[id][i]; que[id][i] = que[id][min]; que[id][min] = t; i = min; } } int main() { int q, Q, K; Q = (int)in(), K = (int)in(); while (Q--) { q = gc(), gc(); if (q == '1') { enq(0, -in()); if (qsize[0] == K) enq(1, -que[0][0]), deq(0); } else if (!qsize[1]) pc('-'), pc('1'), pc('\n'); else out(que[1][0]), deq(1); } return 0; }