#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
const int maxn = 1e5+10;
const double inf = 10000000000000;
int n;
long double a[maxn], b[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
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);
if (n <= 10) {
long double sol = 0;
const int lim = 1 << n;
for (int i = 0; i < lim; i++) {
for (int j = 0; j < lim; j++) {
int kol = __builtin_popcount(i) + __builtin_popcount(j);
long double a = 0;
long double b = 0;
for (int x = 0; x < n; x++)
if (i & (1 << x)) a += ::a[x];
for (int x = 0; x < n; x++)
if (j & (1 << x)) b += ::b[x];
sol = max(sol, min(a, b) - kol);
}
}
cout << fixed << setprecision(4) << sol << endl;
return 0;
}
long double sol = 0;
long double x = 0, y = 0;
int ptrx = 0, ptry = 0;
//a[n] = -inf, b[n] = -inf;
while (ptrx < n || ptry < n) {
//cout << "debug: " << x << " " << y << endl;
//system("pause");
if (ptrx < n && (min(x + a[ptrx] - 1, y - 1) > min(x - 1, y + b[ptry] - 1) || (min(x + a[ptrx] - 1, y - 1) == min(x - 1, y + b[ptry] - 1) && max(x + a[ptrx] - 1, y - 1) > max(x - 1, y + b[ptrx] - 1)))) {
x += a[ptrx++] - 1.0;
y -= 1.0;
} else {
y += b[ptry++] - 1.0;
x -= 1.0;
}
if (ptrx + ptry == 1) sol = min(x, y);
else sol = max(sol, min(x, y));
}
cout << fixed << setprecision(4) << sol << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
74 ms |
504 KB |
Output is correct |
4 |
Correct |
76 ms |
384 KB |
Output is correct |
5 |
Correct |
90 ms |
504 KB |
Output is correct |
6 |
Correct |
85 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
74 ms |
504 KB |
Output is correct |
4 |
Correct |
76 ms |
384 KB |
Output is correct |
5 |
Correct |
90 ms |
504 KB |
Output is correct |
6 |
Correct |
85 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
440 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
74 ms |
504 KB |
Output is correct |
4 |
Correct |
76 ms |
384 KB |
Output is correct |
5 |
Correct |
90 ms |
504 KB |
Output is correct |
6 |
Correct |
85 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
440 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
119 ms |
3568 KB |
Output is correct |
18 |
Correct |
147 ms |
3576 KB |
Output is correct |
19 |
Correct |
123 ms |
3504 KB |
Output is correct |
20 |
Correct |
123 ms |
3560 KB |
Output is correct |
21 |
Correct |
108 ms |
3512 KB |
Output is correct |
22 |
Correct |
128 ms |
4892 KB |
Output is correct |
23 |
Correct |
111 ms |
4856 KB |
Output is correct |
24 |
Correct |
102 ms |
4912 KB |
Output is correct |
25 |
Correct |
101 ms |
4856 KB |
Output is correct |
26 |
Correct |
118 ms |
5240 KB |
Output is correct |