#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;
double a[1000005],b[1000005],p[100005],ans,y,z,p1[100005];
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);
	reverse(a+1,a+n+1);
	for (int i=1; i<=n; i++){
		p1[i]=p1[i-1]+b[i];
		p[i]=p[i-1]+a[i];
	}
	
	for (int i=1; i<=2*n; i++){
		
		for (int j=0; j<=n; j++){
			if (i-j>n || i-j<0) continue;
			ans=max(ans,min(p[j],p1[i-j])-i);
		}
		//cout<<ans<<endl;
	}
	
	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... |