#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second
#define __builtin_popcount __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(x) ((1ll << (x)))
#define debug(a, l, r) for (int _i = (l); _i <= (r); ++_i) cout << (a)[_i] << ' '; cout << '\n';
int n;
signed main() {
#ifdef NCTHANH
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
cin >> n;
vector<ld> a, b;
for (int i = 1; i <= n; ++i) {
ld x, y; cin >> x >> y;
a.push_back(x);
b.push_back(y);
}
sort(all(a));
sort(all(b));
ld suma = 0, sumb = 0, res = 0;
int iter = 0;
while (!a.empty() || !b.empty()) {
if (a.empty()) {
ld cur = b.back(); b.pop_back();
// cout << cur << '\n';
sumb += cur;
}
else if (b.empty()) {
ld cur = a.back(); a.pop_back();
// cout << cur << '\n';
suma += cur;
}
else if (suma < sumb) {
ld cur = a.back(); a.pop_back();
// cout << cur << '\n';
suma += cur;
}
else {
ld cur = b.back(); b.pop_back();
// cout << cur << '\n';
sumb += cur;
}
++iter;
// if (iter == 10) break;
res = max(res, min(suma, sumb) - (ld)iter);
}
cout << fixed << setprecision(4);
cout << res;
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... |