#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 1e5 + 5;
const ld eps = 1e-9;
const ld M = 1e9;
ld a[mn], b[mn], pre_a[mn], pre_b[mn];
int n;
bool ok (ld lb) {
// check if there exist an answer >= lb
for (int k = 0; k <= 2 * n; k++) {
if (pre_a[min(n, k)] < lb + k) continue;
int best = min(n, k);
for (int b = min(n, k); b >= 1; b /= 2) {
while (best - b >= 0 && pre_a[best - b] >= lb + k) best -= b;
}
if (pre_b[min(n, k - best)] >= lb + k) return 1;
}
return 0;
}
ld bs (ld L, ld R) {
if (abs(L - R) < eps) return L;
ld mid = (L + R) / 2.0;
if (ok(mid + eps)) return bs(mid + eps, R);
return bs(L, mid);
}
bool compare (ld a, ld b) { return a > b; }
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
sort(a + 1, a + 1 + n, compare);
sort(b + 1, b + 1 + n, compare);
for (int i = 1; i <= n; i++) {
pre_a[i] = pre_a[i - 1] + a[i];
pre_b[i] = pre_b[i - 1] + b[i];
}
cout << fixed << setprecision(4) << bs(0, M) << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
4 ms |
2596 KB |
Output is correct |
13 |
Correct |
4 ms |
2396 KB |
Output is correct |
14 |
Correct |
5 ms |
2396 KB |
Output is correct |
15 |
Correct |
4 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
4 ms |
2596 KB |
Output is correct |
13 |
Correct |
4 ms |
2396 KB |
Output is correct |
14 |
Correct |
5 ms |
2396 KB |
Output is correct |
15 |
Correct |
4 ms |
2396 KB |
Output is correct |
16 |
Correct |
4 ms |
2396 KB |
Output is correct |
17 |
Correct |
469 ms |
8072 KB |
Output is correct |
18 |
Correct |
561 ms |
8076 KB |
Output is correct |
19 |
Correct |
605 ms |
8068 KB |
Output is correct |
20 |
Correct |
474 ms |
8068 KB |
Output is correct |
21 |
Correct |
417 ms |
8276 KB |
Output is correct |
22 |
Correct |
499 ms |
8020 KB |
Output is correct |
23 |
Correct |
517 ms |
8020 KB |
Output is correct |
24 |
Correct |
603 ms |
8324 KB |
Output is correct |
25 |
Correct |
464 ms |
8068 KB |
Output is correct |
26 |
Correct |
436 ms |
8440 KB |
Output is correct |