#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;
    });
    // for (auto tt : sortf) {
    //     cout << tt.first << ' ' << tt.second << '\n';
    // }
    // cout << '\n';
    // for (auto tt : sorts) {
    //     cout << tt.first << ' ' << tt.second << '\n';
    // }
    double stavim = max(sortf[0].first, sorts[0].second);
    double rs = inf;
    if (stavim == sortf[0].first) {
        double zxc = 0;
        int cc = stavim;
        for (int i = 0; i < min(cc - 1, (int)sorts.size()); ++i) {
            zxc += sorts[i].second;
        }
        rs = min(rs, zxc - cc);
    } else if (stavim == sorts[0].second) {
        double zxc = 0;
        int cc = stavim;
        for (int i = 0; i < min(cc - 1, (int)sortf.size()); ++i) {
            zxc += sortf[i].first;
        }
        rs = min(rs, zxc - cc);
    }
    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... |