64分求助
查看原帖
64分求助
1211899
Bobi2014楼主2024/10/2 20:02

提交记录

提交记录

代码

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
double a[N],b[N],ans,suma,sumb;
int n;
bool cmp(double x,double y){
	return x > y;
}
int main(){
	cin >> n;
	for(int i = 1;i <= n;i ++){
		cin >> a[i] >> b[i];
	}
	sort(a + 1,a + n + 1,cmp);
	sort(b + 1,b + n + 1,cmp);
	for(int l = 1,r = 0;l <= n;l ++){
		suma += a[l];
		while(r < n and sumb < suma){
			sumb += b[++r]; 
		}
		ans = max(ans,min(suma,sumb) - l - r);
	}
	cout << fixed << setprecision(4) << ans;
	return 0;
}

2024/10/2 20:02
加载中...