use std::{cmp::Reverse, collections::BinaryHeap}; macro_rules! read_line { ($($xs: tt)*) => { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); expand!(iter, $($xs)*); }; } macro_rules! expand { ($iter: expr,) => {}; ($iter: expr, mut $var: ident : $type: tt, $($xs: tt)*) => { let mut $var = value!($iter, $type); expand!($iter, $($xs)*); }; ($iter: expr, $var: ident : $type: tt, $($xs: tt)*) => { let $var = value!($iter, $type); expand!($iter, $($xs)*); }; } macro_rules! value { ($iter:expr, ($($type: tt),*)) => { ($(value!($iter, $type)),*); }; ($iter: expr, [$type: tt; $len: expr]) => { (0..$len).map(|_| value!($iter, $type)).collect::>() }; ($iter: expr, Chars) => { value!($iter, String).chars().collect::>>() }; ($iter: expr, $type: ty) => { if let Some(v) = $iter.next() { v.parse::<$type>().ok() } else { None } }; } fn main() { read_line! { q: usize, k: usize, } let (q, k) = (q.unwrap(), k.unwrap()); let mut pql = BinaryHeap::new(); let mut pqr = BinaryHeap::new(); for _ in 0..q { read_line! { t: usize, v: usize, } let t = t.unwrap(); if t == 1 { let v = v.unwrap(); if pql.len() < k { pql.push(v); } else { pql.push(v); pqr.push(Reverse(pql.pop().unwrap())); } } else { if pql.len() < k { println!("-1"); } else { println!("{}", pql.pop().unwrap()); if let Some(Reverse(u)) = pqr.pop() { pql.push(u); } } } } }