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() { Some(v.parse::<$type>().unwrap()) } 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(); let v = vec![1, 2, 3]; v.into_iter().next(); 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 { if *pql.peek().unwrap() <= v { pqr.push(Reverse(v)); } else { let u = pql.pop().unwrap(); pql.push(v); pqr.push(Reverse(u)); } } } else { if pql.len() < k { println!("-1"); } else { println!("{}", pql.pop().unwrap()); if let Some(Reverse(u)) = pqr.pop() { pql.push(u); } } } } }