#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ar array
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
signed main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
int N; cin >> N;
vector<double> a(N), b(N);
vector<double> suma(N), sumb(N);
for (int i = 0; i < N; ++i) {
cin >> a[i] >> b[i];
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
for (int i = 0; i < N; ++i) {
suma[i] = a[i];
sumb[i] = b[i];
if (i) suma[i] += suma[i - 1];
if (i) sumb[i] += sumb[i - 1];
}
double res = 0;
for (int i = 0, j = 0; i < N; ++i) {
while (j < N - 1 && sumb[j] < suma[i])
++j;
res = max(res, min(suma[i], sumb[j]) - i - j - 2);
}
for (int i = 0, j = 0; i < N; ++i) {
while (j < N - 1 && suma[j] < sumb[i])
++j;
res = max(res, min(sumb[i], suma[j]) - i - j - 2);
}
cout << fixed << setprecision(4) << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
91 ms |
4856 KB |
Output is correct |
18 |
Correct |
90 ms |
4856 KB |
Output is correct |
19 |
Correct |
91 ms |
4856 KB |
Output is correct |
20 |
Correct |
91 ms |
4908 KB |
Output is correct |
21 |
Correct |
99 ms |
5184 KB |
Output is correct |
22 |
Correct |
91 ms |
4856 KB |
Output is correct |
23 |
Correct |
91 ms |
4856 KB |
Output is correct |
24 |
Correct |
96 ms |
4800 KB |
Output is correct |
25 |
Correct |
93 ms |
4876 KB |
Output is correct |
26 |
Correct |
97 ms |
5240 KB |
Output is correct |