#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using ll=long long; using T=tuple; void IO(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main(){ IO(); ll n,x,y; cin>>n>>x>>y; vector p(n); vector c(n); for(ll i=0;i>p[i]>>c[i]; } if(n<=x+y){ ll ans=0; for(ll i=0;i0){ x--; ans+=p[i]; } }else{ if(y>0){ y--; ans+=p[i]; } } } cout< sum_a(x+y); vector sum_b(x+y); for(ll i=0;i v; for(ll i=0;i fin_idx,second_idx; for(ll i=0;i<(ll)v.size();i++){ ll val=get<0>(v[i]); ll idx=get<1>(v[i]); ll t=get<2>(v[i]); if(fin_idx.find(idx)==fin_idx.end()){ if(second_idx.find(idx)==second_idx.end()){ if(t==0&&rx>0){ rx--; fin_idx.insert(idx); ans+=val; }else if(t==1&&ry>0){ ry--; fin_idx.insert(idx); ans+=val; }else{ second_idx.insert(idx); } }else{ if(t==0){ ry--; fin_idx.insert(idx); second_idx.erase(idx); ans+=val; }else{ rx--; fin_idx.insert(idx); second_idx.erase(idx); ans+=val; } } } } cout<