显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a,b,c,d,ans;
vector<int>v;
unordered_map<int,int>h;
signed main(){
freopen("Compatible.in","r",stdin);
freopen("Compatible.out","w",stdout);
scanf("%lld %lld %lld",&n,&a,&b);
for(int i=1;i<=n;i++){
scanf("%lld %lld",&c,&d);
h[d]=c;v.push_back(d);
}
sort(v.begin(),v.end());
swap(a,b);
for(auto s:v){
int x;
x=a-s;
if(x>=0&&h[x]>0){
if(x==s){
ans+=h[x]/2;
h[x]%=2;
}else{
int tmp=min(h[x],h[s]);
h[x]-=tmp,h[s]-=tmp;
ans+=tmp;
}
}
x=b-s;
if(x>=0&&h[x]>0){
if(x==s){
ans+=h[x]/2;
h[x]%=2;
}else{
int tmp=min(h[x],h[s]);
h[x]-=tmp,h[s]-=tmp;
ans+=tmp;
}
}
}
printf("%lld\n",ans);
return 0;
}