#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
double a[n], b[n];
iloop(0, n) cin >> a[i] >> b[i];
sort(a, a+n);
sort(b, b+n);
double cans = 0, ca1 = 0, ca2 = 0, cv = 0;
ll cn1 = n-1, cn2 = n-1;
iloop(0, 2*n) {
cv++;
if (cn1 == -1 || ca1 > ca2) {
ca2 += b[cn2];
cn2--;
}
else {
ca1 += a[cn1];
cn1--;
}
cans = max(cans, min(ca1, ca2) - cv);
}
cout << fixed << setprecision(4) << cans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |