#include //#include //#include using namespace std; //using namespace atcoder; //using namespace boost::multiprecision; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long ll; typedef pair P; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template T gcd(T a,T b){return b?gcd(b,a%b):a;} const ll mod=998244353; const ll LINF=1ll<<60; const int INF=1<<30; int dx[]={1,0,-1,0,1,-1,1,-1}; int dy[]={0,1,0,-1,1,-1,-1,1}; template< typename T > struct BinaryIndexedTree{ //0-indexed vector< T > bit; BinaryIndexedTree(int sz) : bit(sz, 0) {} //return a[0, k) T sum(int k){ assert(0 <= k && k <= bit.size()); T ret = 0; for (--k; k >= 0; k = (k&(k+1))-1) ret += bit[k]; return ret; } //return a[l, r) T sum(int l, int r){ return sum(r) - sum(l); } //a[k] += k void add(int k, T x){ for (; k < bit.size(); k |= k+1) bit[k] += x; } //a[k] = x void update(int k, T x){ add(k, x - sum(k, k + 1)); } // sum(ret) >= x を満たす最小のret T lower_bound(T x) { if(x <= 0) return 0; T ret = 0; int i = 1; while((i<<1) < bit.size()) i <<= 1; for(;i;i>>=1){ if(ret+i-1 < bit.size() && bit[ret+i-1] < x){ x -= bit[ret + i - 1]; ret += i; } } return ret + 1; } }; int main(){ int q, k;cin >> q >> k; BinaryIndexedTree bit(200001); vector

v(q, mp(0,0)); vector x; for (int i = 0; i < q; i++) { int t;cin >> t; if(t == 1){ ll X;cin >> X; x.pb(X); v[i] = mp(t, X); } else{ v[i] = mp(t, 0); } } sort(ALL(x)); x.erase(unique(ALL(x)), x.end()); for (int i = 0; i < q; i++) { if(v[i].fs == 1){ auto p = lower_bound(ALL(x), v[i].sc) - x.begin(); bit.add(p, 1); } else{ auto p = bit.lower_bound(k); if(p > 200000){ cout << -1 << endl; } else{ cout << x[p - 1] << endl; bit.add(p - 1, -1); } } } return 0; }