比赛 NOIP2025模拟赛2 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 博彩游戏 最终得分 100
用户昵称 徐诗畅 运行时间 0.846 s
代码语言 C++ 内存使用 4.41 MiB
提交时间 2025-11-25 09:39:23
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
double a[N],b[N],f[N][2][2];
bool cmp(double x,double y){return x>y;}
int main(){
	freopen("wager.in","r",stdin);
	freopen("wager.out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i<=n;i++)
	scanf("%lf%lf",&a[i],&b[i]);
	sort(a+1,a+1+n,cmp); sort(b+1,b+1+n,cmp);
	double ans=0,s1=0,s2=b[1];
	int pos=1;
	for(int i = 1;i<=n;i++){
		s1+=a[i];
		while(s2<s1&&pos<n){
			pos++;
			s2+=b[pos];
		}
		if(s2<s1) break;
		ans=max(ans,s1-(i+pos));
	}
	s1=0; s2=a[1]; pos=1;
	for(int i = 1;i<=n;i++){
		s1+=b[i];
		while(s2<s1&&pos<n){
			pos++;
			s2+=a[pos];
		}
		if(s2<s1) break;
		ans=max(ans,s1-(i+pos));
	}
	printf("%.4lf",ans);
	return 0;
}