#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 <double> st1;
multiset <double> st2;
void salemkhan() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
st1.insert(a[i]);
st2.insert(b[i]);
}
double ans = 0;
double sum1 = 0;
double sum2 = 0;
ll l = 1;
while(l <= n * 2) {
if(sum2 > sum1) {
if(st1.size() == 0) break;
auto it1 = *st1.rbegin();
sum1 += it1;
st1.erase(st1.find(it1));
}
else {
if(st2.size() == 0) break;
auto it2 = *st2.rbegin();
sum2 += it2;
st2.erase(st2.find(it2));
}
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... |