// use std::ops::{Index, IndexMut}; // use std::cmp::{Ordering, min, max}; // use std::collections::{BinaryHeap, BTreeMap}; // use std::collections::btree_map::Entry::{Occupied, Vacant}; // use std::clone::Clone; fn getline() -> String { let mut res = String::new(); std::io::stdin().read_line(&mut res).ok(); res } macro_rules! readl { ($t: ty) => { { let s = getline(); s.trim().parse::<$t>().unwrap() } }; ($( $t: ty),+ ) => { { let s = getline(); let mut iter = s.trim().split(' '); ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) } }; } macro_rules! readlvec { ($t: ty) => { { let s = getline(); let iter = s.trim().split(' '); iter.map(|x| x.parse().unwrap()).collect::>() } } } macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } } fn printiter<'a, T>(v: &'a T) where &'a T: std::iter::IntoIterator, <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display, { for (i, e) in v.into_iter().enumerate() { if i != 0 { print!(" "); } print!("{}", e); } println!(""); } struct ContestPrinter { s: String, } impl ContestPrinter { fn new() -> ContestPrinter { ContestPrinter { s: String::new() } } fn print(&mut self, x: T) where T: std::fmt::Display, { self.s.push_str(format!("{}", x).as_str()); } fn println(&mut self, x: T) where T: std::fmt::Display, { self.s.push_str(format!("{}\n", x).as_str()); } } impl std::ops::Drop for ContestPrinter { fn drop(&mut self) { print!("{}", self.s); } } trait Monoid { fn unity() -> Self; fn op(&self, &Self) -> Self; } #[derive(Clone)] struct SegmentTree { dat: Vec, length: usize, } impl SegmentTree { fn new(n: usize) -> SegmentTree { let mut len = 1; while len < n { len <<= 1; } SegmentTree { dat: vec![T::unity(); len*2], length: n, } } fn len(&self) -> usize { self.length } fn update(&mut self, i: usize, val: T) { assert!(i < self.len()); let mut p = self.dat.len()/2-1+i; self.dat[p] = val; while p != 0 { p = (p-1)/2; self.dat[p] = self.dat[2*p+1].op(&self.dat[2*p+2]); } } fn query(&self, l: usize, r: usize) -> T { self.query_(l, r, 0, 0, self.dat.len()/2) } fn get(&self, ind: usize) -> T { self.dat[self.dat.len()/2+ind-1].clone() } fn query_(&self, l: usize, r: usize, i: usize, a: usize, b: usize) -> T { if l <= a && b <= r { self.dat[i].clone() } else if !(r <= a || b <= l) { let retl = self.query_(l, r, i*2+1, a, (a+b)/2); let retr = self.query_(l, r, i*2+2, (a+b)/2, b); retl.op(&retr) } else { T::unity() } } // fn debug(&self) { // printvec(&self.dat); // } } fn main() { let mut printer = ContestPrinter::new(); let (q, k) = readl!(usize, usize); let mut qul = std::collections::BinaryHeap::new(); let mut qur = std::collections::BinaryHeap::new(); for _ in 0..q { let qu = readlvec!(i64); if qu.len() == 2 { qul.push(qu[1]); if qul.len() > k { qur.push(-qul.pop().unwrap()); } } else { if qul.len() < k { printer.println(-1); } else { printer.println(qul.pop().unwrap()); if let Some(v) = qur.pop() { qul.push(-v); } } } } }