#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 100'010;
double a[N], b[N];
int n;
template<class T>
pair<double, int> ter(T f, int l, int r)
{
--r;
while (l < r) {
int m = (l+r)/2;
if (f(m) < f(m+1))
l = m+1;
else
r = m;
}
return {f(l), l};
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n;
Loop (i,1,n+1) {
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);
Loop (i,0,n) {
a[i+1] += a[i];
b[i+1] += b[i];
}
reverse(b, b+n+1);
double ans = 0;
Loop (j,0,n+1) {
auto [x, i] = ter([&](int i){return min(a[i], b[j+i]);}, 0, n+1-j);
ans = max(ans, x - (n - j));
}
Loop (i,1,n+1) {
auto [x, j] = ter([&](int j){return min(a[i+j], b[j]);}, 0, n+1-i);
ans = max(ans, x - (n + i));
}
cout << fixed << setprecision(4) << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
85 ms |
1868 KB |
Output is correct |
18 |
Correct |
83 ms |
3116 KB |
Output is correct |
19 |
Correct |
83 ms |
3148 KB |
Output is correct |
20 |
Correct |
94 ms |
3156 KB |
Output is correct |
21 |
Correct |
88 ms |
3608 KB |
Output is correct |
22 |
Correct |
81 ms |
3240 KB |
Output is correct |
23 |
Correct |
88 ms |
3192 KB |
Output is correct |
24 |
Correct |
90 ms |
3340 KB |
Output is correct |
25 |
Correct |
82 ms |
3136 KB |
Output is correct |
26 |
Correct |
90 ms |
3508 KB |
Output is correct |