void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.container; int q, k; rd(q, k); auto qmax=new BinaryHeap!(Array!(long))(), qmin=new BinaryHeap!(Array!(long), "a>b")(); while(q--){ auto args=readln.split.to!(long[]); if(args[0]==1){ auto v=args[1]; if(qmax.length=k){ writeln(qmax.front); qmax.popFront; if(qmax.length0){ qmax.insert(qmin.front); qmin.popFront; } }else{ writeln(-1); } } } } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }