use std::{collections::BinaryHeap, cmp::Reverse}; fn main() { let mut qk = String::new(); std::io::stdin().read_line(&mut qk).ok(); let qk: Vec = qk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let q = qk[0]; let k = qk[1]; let queries = (0..q).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); temp }) .collect::>(); let mut targets = BinaryHeap::new(); let mut rests = BinaryHeap::new(); for v in queries.iter() { if v[0] == 1 { targets.push(v[1]); if targets.len() > k { rests.push(Reverse(targets.pop().unwrap())); } } else { if targets.len() == k { println!("{}", targets.pop().unwrap()); if let Some(Reverse(val)) = rests.pop() { targets.push(val); } } else { println!("-1"); } } } }