This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//I love armpit fetish
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"
const int MAX_N = 100002;
int n;
double A[MAX_N], B[MAX_N];
void enter() {
cin >> n;
for (int i=1; i<=n; ++i) {
cin >> A[i] >> B[i];
}
sort(A+1, A+n+1);
sort(B+1, B+n+1);
reverse(A+1, A+n+1);
reverse(B+1, B+n+1);
for (int i=1; i<=n; ++i) {
A[i] += A[i-1];
B[i] += B[i-1];
}
}
double bisect(int v) {
int l = 0, r = min(v, n);
while (r-l+1>=3) {
int mid1 = l + (r - l + 1) / 3;
int mid2 = r - (r - l + 1) / 3;
if (min(A[mid1], B[v-mid1]) > min(A[mid2], B[v-mid2]))
r = mid2;
else
l = mid1;
}
double res = 0;
for (int i=l; i<=r; ++i)
res = max(res, min(A[i], B[v-i]));
return res;
}
void solve() {
double res = 0;
//PR(A, n);
//PR(B, n);
//debug(bisect(5) - 5);
for (int i=1; i<=2*n; ++i)
res = max(res, bisect(i) - i);
cout << setiosflags(ios::fixed) << setprecision(4) << res;
}
int main() {
//#define OFFLINE_JUDGE doraemon
#ifdef OFFLINE_JUDGE
freopen(FILE_NAME".inp", "r", stdin);
freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
enter();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |