#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector <double> v1(n), v2(n);
for (int i = 0; i < n; i++)
cin >> v1[i] >> v2[i];
sort(v1.rbegin(), v1.rend());
sort(v2.rbegin(), v2.rend());
for (int i = 1; i < n; i++)
v1[i] += v1[i - 1], v2[i] += v2[i - 1];
auto solve = [](vector <double>& v, vector <double>& oth) -> double {
double best = 0;
for (int i = 0; i < v.size(); i++) {
/// iau prefixul de lungime i din v
int loc = lower_bound(oth.begin(), oth.end(), v[i]) - oth.begin();
if (loc != oth.size())
best = max(best, min(v[i], oth[loc]) - i - loc - 2);
if (loc != 0)
best = max(best, min(v[i], oth[loc - 1]) - i - loc - 1);
}
return best;
};
double ans = max(solve(v1, v2), solve(v2, v1));
cout << setprecision(4) << fixed << ans << '\n';
return 0;
}
Compilation message
sure.cpp: In lambda function:
sure.cpp:26:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v.size(); i++) {
~~^~~~~~~~~~
sure.cpp:29:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (loc != oth.size())
~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
95 ms |
3244 KB |
Output is correct |
18 |
Correct |
94 ms |
3320 KB |
Output is correct |
19 |
Correct |
96 ms |
3320 KB |
Output is correct |
20 |
Correct |
100 ms |
3324 KB |
Output is correct |
21 |
Correct |
123 ms |
3692 KB |
Output is correct |
22 |
Correct |
95 ms |
3336 KB |
Output is correct |
23 |
Correct |
92 ms |
3320 KB |
Output is correct |
24 |
Correct |
94 ms |
3320 KB |
Output is correct |
25 |
Correct |
92 ms |
3320 KB |
Output is correct |
26 |
Correct |
99 ms |
3740 KB |
Output is correct |