#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
#define rep(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MAXN = 2e5 + 5;
int n;
ld a[MAXN];
ld b[MAXN];
int main() {
FAST_IO;
cout.precision(10);
cout.setf(ios::fixed);
cin >> n;
rep(i, n) {
cin >> a[i] >> b[i];
}
sort(a, a + n);
sort(b, b + n);
reverse(a, a + n);
reverse(b, b + n);
// ld res = 0;
// ld s1 = 0;
// rep(i, n) {
// s1 += a[i];
// ld s2 = 0;
// rep(j, n) {
// s2 += b[j];
// res = max(res, min(s1, s2) - i - j - 2);
// }
// }
// cout << res << endl;
ld s1 = 0, s2 = 0;
int p1 = 0, p2 = 0;
ld res = 0;
for (int c = 0; c < n * 2; ++c) {
if (s1 < s2 && p1 < n) {
s1 += a[p1++];
} else {
s2 += b[p2++];
}
res = max(res, min(s1, s2) - c - 1);
}
// cout << res << endl;
printf("%.4lf",(double)res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
113 ms |
3548 KB |
Output is correct |
18 |
Correct |
112 ms |
3628 KB |
Output is correct |
19 |
Correct |
113 ms |
3704 KB |
Output is correct |
20 |
Correct |
113 ms |
3656 KB |
Output is correct |
21 |
Correct |
125 ms |
3664 KB |
Output is correct |
22 |
Correct |
112 ms |
4856 KB |
Output is correct |
23 |
Correct |
113 ms |
4864 KB |
Output is correct |
24 |
Correct |
113 ms |
4856 KB |
Output is correct |
25 |
Correct |
113 ms |
4788 KB |
Output is correct |
26 |
Correct |
121 ms |
5240 KB |
Output is correct |