记录编号 605724 评测结果 AAAAAAAAAAAA
题目名称 4171.[USACO25 Open Silver]Compatible Pairs 最终得分 100
用户昵称 Gravatar左清源 是否通过 通过
代码语言 C++ 运行时间 1.221 s
提交时间 2025-09-06 17:21:10 内存使用 10.78 MiB
显示代码纯文本
#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;
}