#ifdef SENJAN #define _GLIBCXX_DEBUG #else #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include #include #include using namespace std; using namespace atcoder; using ll=long long; using ull=unsigned long long; using ld=long double; using bint = boost::multiprecision::cpp_int; using graph=vector>; template using min_priority_queue=priority_queue,greater>; constexpr int INF32=INT_MAX/2; constexpr ll INF64=LLONG_MAX/2; constexpr ld PI=3.14159265358979323846; constexpr int dx[]={0,0,-1,1,-1,-1,1,1},dy[]={-1,1,0,0,-1,1,-1,1}; template inline bool chmax(T &a,T b){return a inline bool chmin(T &a,T b){return a>b?a=b,true:false;} inline void dispYN(bool a){cout<<(a?"YES":"NO")<sync_with_stdio(0);cout<> n >> m; vector used(n); min_priority_queue> x_c, y_c; for(int i=0; i> a; x_c.push({a,i}); } for(int i=0; i> b; y_c.push({b,i}); } min_priority_queue x_p, y_p; for(int i=0; i> t >> c; if(t==0) x_p.push(c); if(t==1) y_p.push(c); } int ans = n; while(!x_c.empty() && !y_c.empty()){ auto cmp = [&](){ if(x_c.empty()) return false; if(y_c.empty()) return true; if(x_c.top()==y_c.top()){ if(x_p.empty()) return false; if(y_p.empty()) return true; return (x_p.top()<=y_p.top()); } return (x_c.top().first<=y_c.top().first); }; if(cmp()){ auto [val,idx] = x_c.top(); x_c.pop(); while(!x_p.empty() && x_p.top()