#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,sse4a,abm,mmx,avx,avx2,fma,popcnt,tune=native")
#define int long long
#define qweqdasd ios_base::sync_with_stdio(0), cin.tie(0)
#define pb push_back
#define st first
#define nd second
#define watch(x) (cout << #x << " == " << x << '\n')
mt19937_64 rng(147098291);
random_device rd;
mt19937_64 mersenne(rd());
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const int mod2 = (119 << 23) + 1; // 998244353
const int inf = 1e18;
const double eps = 1e-7;
const int block = 350;
const int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
const int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };
int a[maxn];
void solve()
{
    int n;
    cin >> n;
    vector<pair<double, double>> vec;
    for (int i = 1; i <= n; ++i) {
        double x, y;
        cin >> x >> y;
        vec.pb({ x, y });
    }
    vector<pair<double, double>> sortf = vec;
    sort(sortf.begin(), sortf.end(), [](const pair<double, double>& ff, const pair<double, double>& ss) {
        return ff.first > ss.first;
    });
    vector<pair<double, double>> sorts = vec;
    sort(sorts.begin(), sorts.end(), [](const pair<double, double>& ff, const pair<double, double>& ss) {
        return ff.second > ss.second;
    });
    double preff[n + 1], prefs[n + 1];
    preff[0] = prefs[0] = 0;
    for (int i = 1; i <= n; ++i) {
        preff[i] = preff[i - 1] + sortf[i - 1].first;
    }
    for (int i = 1; i <= n; ++i) {
        prefs[i] = prefs[i - 1] + sorts[i - 1].second;
    }
    double rs = 0;
    for (int i = 1; i <= n; ++i) {
        int low = 1, high = n;
        int bsrs = 0;
        while (low <= high) {
            int mid = (low + high) >> 1;
            if (preff[i] <= prefs[mid]) {
                high = mid - 1;
                bsrs = mid;
            } else {
                low = mid + 1;
            }
        }
        rs = max(rs, preff[i] - bsrs - i);
    }
    for (int j = 1; j <= n; ++j) {
        int low = 1, high = n;
        int bsrs = 0;
        while (low <= high) {
            int mid = (low + high) >> 1;
            if (prefs[j] > preff[mid]) {
                bsrs = mid;
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        rs = max(rs, preff[bsrs] - bsrs - j);
    }
    cout << setprecision(4) << fixed << max(rs, 0.0);
}
int32_t main()
{
    qweqdasd;
    int tests = 1;
    // cin >> tests;
    for (int i = 1; i <= tests; ++i) {
        // cout << "Case " << i << ":\n";
        solve();
    }
#ifdef LOCAL
    cerr << '\n'
         << "fnshd in " << clock() * 1.0 / CLOCKS_PER_SEC << " s\n";
#endif
}
/**
 *
 */
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |