题目链接:Codeforces - Debate
我们可以发现,拿状态为"11",的就是白拿,因为权值都为正,所以肯定拿。
其次,对于状态"10"和"01",一起拿,也是不影响的。所有直接拿。
然后就剩下"00"和"10"或者"00"和"01",选最大的,状态"11"的个数。
AC代码:
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=4e5+10;
int n,cnt,res; string str;
priority_queue<int> q[4],pq;
signed main(){
cin>>n;
for(int i=1,x,s;i<=n;i++){
x=0; cin>>str>>s;
for(int j=0;j<2;j++) if(str[j]=='1') x|=(1<<j); q[x].push(s);
}
while(q[3].size()) cnt++,res+=q[3].top(),q[3].pop();
while(q[2].size()&&q[1].size()) res+=q[2].top()+q[1].top(),q[1].pop(),q[2].pop();
for(int i=0;i<=2;i++) while(q[i].size()) pq.push(q[i].top()),q[i].pop();
while(cnt&&pq.size()) res+=pq.top(),cnt--,pq.pop();
cout<<res;
return 0;
}