// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
#include <numeric>
#include <stack>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
void fast_io() {
// freopen("", "r", stdin);
// freopen("", "w", stdout);
ios::sync_with_stdio(0);
cin.tie();
cout.tie();
cout << setprecision(9);
}
#define int long long
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void solve() {
int n; cin >> n;
vector<long double> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
sort(rall(a));
sort(rall(b));
int i = 0, j = 0;
long double ans = 0, A = 0, B = 0;
while (i < n && j < n){
if (A < B) A += a[i++];
else B += b[j++];
ans = max(ans, min(A, B) - i - j);
}
while (i < n){
A += a[i++];
ans = max(ans, min(A, B) - i - j);
}
while (j < n){
B += b[j++];
ans = max(ans, min(A, B) - i - j);
}
cout << fixed << setprecision(4) << (double) ans << endl;
}
signed main() {
fast_io();
srand(chrono::steady_clock::now().time_since_epoch().count());
int tc = 1;
// cin >> tc;
while (tc--) solve();
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... |