#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>> ms;
void salemkhan() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
ms.insert({a[i], i});
}
sort(b + 1, b + n + 1);
reverse(b + 1, b + n + 1);
double ans = 0;
double sum1 = 0;
double sum2 = 0;
double cnt = 0;
for(int i = 1; i <= n; i++) {
if(ms.find({a[i], i}) != ms.end()) {
sum1 += b[i];
cnt++;
ms.erase(ms.find({a[i], i}));
}
while(sum1 > sum2 && ms.size()) {
auto it = *ms.rbegin();
sum2 += it.F;
ms.erase(ms.find(it));
cnt++;
double p1 = sum1;
double p2 = sum2;
if(p1 > p2) swap(p1, p2);
if(ans < p1 - cnt) {
ans = p1 - cnt;
}
}
}
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... |