#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define F first
#define S second
#define in insert
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 123;
const int P = 320;
const int mod = 1e9 + 7;
ll n, m, k;
double a[N], b[N];
ll sum[N];
double pref[N];
multiset <pair<double, ll>> st1;
multiset <pair<double, ll>> st2;
void salemkhan() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
st1.insert({a[i], i});
st2.insert({b[i], i});
}
double ans = 0;
double sum1 = 0;
double sum2 = 0;
ll l = 1;
while(l <= n) {
auto it1 = *st1.rbegin();
auto it2 = *st2.rbegin();
if(sum2 > sum1) {
sum1 += it1.F;
st1.erase(st1.find(it1));
st2.erase(st2.find({b[it1.S], it1.S}));
}
else {
sum2 += it2.F;
st2.erase(st2.find(it2));
st1.erase(st1.find({a[it2.S], it2.S}));
}
double p1 = sum1;
double p2 = sum2;
if(p1 > p2) swap(p1, p2);
if(ans < p1 - l) {
ans = p1 - l;
}
l++;
}
cout << fixed;
cout.precision(4);
cout << ans << '\n';
}
// 28 37 48 49 55 56 57 58 67 9
// 9 + 1 +
int main() {
//freopen("knight.in", "r", stdin);
//freopen("knight.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tt = 1;
//cin >> tt;
while(tt--) {
salemkhan();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |