#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int> pii32;
typedef pair<int64,int64> pii64;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
const int maxn = 1e5+10;
const double eps = 1e-9;
const int64 MO = 1e9+7;
const int64 IN = 1e9;
double s1[maxn], s2[maxn];
double a[maxn], b[maxn];
int n;
int g1 (double x) {
if (s1[n - 1] < x)
return n;
int l = -1, r = n - 1, mid;
while (r - l > 1) {
mid = (l + r) >> 1;
if (s1[mid] >= x)
r = mid;
else
l = mid;
}
return r;
}
int g2 (double x) {
if (s2[n - 1] < x)
return n;
int l = -1, r = n - 1, mid;
while (r - l > 1) {
mid = (l + r) >> 1;
if (s2[mid] >= x)
r = mid;
else
l = mid;
}
return r;
}
int main () {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
sort(a, a + n); reverse(a, a + n);
sort(b, b + n); reverse(b, b + n);
s1[0] = a[0];
s2[0] = b[0];
for (int i = 1; i < n; i++) {
s1[i] = s1[i - 1] + a[i];
s2[i] = s2[i - 1] + b[i];
}
double ans = 0;
for (int i = 1; i <= 2 * n; i++) {
double l = 0, r = IN, mid;
while (r - l > eps) {
mid = (l + r) / 2;
int p1 = g1(mid), p2 = g2(mid);
if (p1 == n || p2 == n || p1 + 1 + p2 + 1 > i)
r = mid;
else
l = mid;
}
ans = max(ans, l - i);
}
cout << fixed << setprecision(5) << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |