This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
double odds [2][N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> odds[0][i] >> odds[1][i];
}
sort(odds[0], odds[0] + n, greater<double>());
sort(odds[1], odds[1] + n, greater<double>());
double res = 0;
double val1 = 0;
double val2 = 0;
int a = 0;
int b = 0;
for (int i = 0; i < 2 * n; i++) {
if (i == 0) {
val1 += odds[0][a];
a++;
res = max(res, min(val1, val2) - a - b);
} else {
if (val1 < val2 && a != n) {
val1 += odds[0][a];
a++;
res = max(res, min(val1, val2) - a - b);
} else {
val2 += odds[1][b];
b++;
res = max(res, min(val1, val2) - a - b);
}
}
}
cout << fixed << setprecision(4) << res << "\n";
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |