#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
ll mod=1e9+7;
ll l,r,x,t,n,q,mx,mn,k;
map <ll,ll> m;
bool ok,okk;
string s,s1;
float a[1000005],b[1000005],p[100005],ans,y,z;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    t=1;
    //cin>>t;
    while (t--){
	cin>>n;
	for (int i=1; i<=n; i++){
		cin>>a[i]>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	ans=0; x=0; y=0; z=0;
	reverse(b+1,b+n+1);
	for (int i=1; i<=n; i++){
		p[i]=p[i-1]+b[i];
	}
	for (int i=n; i>=1; i--){
		y+=a[i];
		x=upper_bound(p+1,p+n+1,y)-p;
		if (y>p[n]) x=n;
		ans=max(ans,min(y,p[x])-(x+n-i+1));
		if (x==1) continue;
		x--;
		ans=max(ans,min(y,p[x])-(x+n-i+1));
		if (x==1) continue;
		x--;
		ans=max(ans,min(y,p[x])-(x+n-i+1));
	}
	printf("%.4lf",(double)ans);
//	cout<<ans<<endl;
	}
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |