// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e5+5;
int n;
double a[maxn], b[maxn], pa[maxn], pb[maxn];
double f(int i, int j) {
return min(pa[i], pb[j])-(i+j+2);
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(4);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
sort(a, a+n), sort(b, b+n);
reverse(a, a+n), reverse(b, b+n);
for (int i = 0; i < n; i++) {
pa[i] = a[i], pb[i] = b[i];
if (i) pa[i] += pa[i-1], pb[i] += pb[i-1];
}
double ans = 0;
for (int i = 0; i < n; i++) {
int l = 0, r = n-1;
while (r-l > 5) {
int m1 = l+(r-l)/3, m2 = r-(r-l)/3;
if (f(i, m1) <= f(i, m2)) l = m1;
else r = m2;
}
for (; l <= r; l++) smax(ans, f(i, l));
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2528 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2528 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
77 ms |
4692 KB |
Output is correct |
18 |
Correct |
78 ms |
4752 KB |
Output is correct |
19 |
Correct |
78 ms |
4688 KB |
Output is correct |
20 |
Correct |
77 ms |
4784 KB |
Output is correct |
21 |
Correct |
80 ms |
5460 KB |
Output is correct |
22 |
Correct |
77 ms |
4792 KB |
Output is correct |
23 |
Correct |
81 ms |
4908 KB |
Output is correct |
24 |
Correct |
78 ms |
4688 KB |
Output is correct |
25 |
Correct |
79 ms |
4936 KB |
Output is correct |
26 |
Correct |
81 ms |
5200 KB |
Output is correct |