#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());
// #define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
// const int maxN;
void solve() {
int n;
cin >> n;
double a[n + 1], b[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
int i = 0, j = 0;
double ans = 0;
double cura = 0, curb = 0;
while (1) {
if (i == n && j == n) break;
if (i < n && j == n) cura += a[++i];
else if (i == n && j < n) curb += b[++j];
else if (cura > curb) curb += b[++j];
else if (cura < curb) cura += a[++i];
else if (cura + a[i + 1] < curb + b[i + 1]) cura += a[++i];
else curb += b[++j];
// cout << cura << ' ' << curb << ' ' << i << ' ' << j << '\n';
ans = max(ans, min(cura, curb) - i - j);
} cout << setprecision(4) << fixed << ans;
}
int32_t main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |