#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int) 1e5 + 7;
const ld INF = (ld) 1e9;
ld a[N], b[N];
ld f(int type1, int total) {
if (type1 > total) {
return INF;
}
return min(a[type1], b[total - type1]) - total;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(b + 1, b + n + 1);
for (int i = 1; i <= n; i++) {
a[i] += a[i - 1];
}
for (int i = 1; i <= n; i++) {
b[i] += b[i - 1];
}
ld ret = 0;
for (int i = 1; i <= 2 * n; i++) {
int low = 0, high = min(n, i), sol = 0;
while (low <= high) {
int mid = (low + high) / 2;
if (f(mid, i) < f(mid + 1, i)) {
sol = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
if (sol < min(n, i)) {
sol++;
}
ret = max(ret, f(sol, i));
}
cout << setprecision(4) << fixed << (ld) (((ll) (ret * 1e4)) / 1e4);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |