#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REV(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
void solve()
{
    int n; cin >> n;
    vector<ld> a(n + 1), b(n + 1);
    FOR(i, 1, n) cin >> a[i] >> b[i];
    sort(1 + all(a), greater<ld>());
    sort(1 + all(b), greater<ld>());
    FOR(i, 1, n) a[i] += a[i - 1], b[i] += b[i - 1];
    /*
        For each number of times we choose to bet
        + Will always choose 2 prefix a and prefix b that has the smallest abs
        + (i + j) = choose time
    */
    ld answer = 0;
    for(int i = 1, j = 0; i <= n; i++){
        while(j <= n && b[j] < a[i]){
            answer = max(answer, b[j] - (i + j));
            j++;
        }
        if(j <= n) answer = max(answer, a[i] - (i + j));
        answer = max(answer, b[j - 1] - (i + j - 1));
    }
    cout << fixed << setprecision(4) << answer << "\n";
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }
    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sure.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |