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];
double sum[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;
sum[0][0] = odds[0][0];
sum[1][0] = odds[1][0];
for (int i = 1; i < n; i++) {
for (int j = 0; j < 2; j++) sum[j][i] = sum[j][i - 1] + odds[j][i];
}
for (int i = 0; i < n; i++) {
double val1 = sum[0][i];
int a = 0;
int b = n - 1;
while (a < b) {
int mid = (a + b) / 2;
double res1 = min(val1, sum[1][mid]) - i - mid - 2;
double res2 = min(val1, sum[1][mid + 1]) - i - (mid + 1)- 2;
res = max(res, res1);
res = max(res, res2);
if (res1 > res2) {
b = mid;
} else {
a = mid + 1;
}
}
}
cout << fixed << setprecision(4) << res << "\n";
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:24:12: warning: unused variable 'val1' [-Wunused-variable]
24 | double val1 = 0;
| ^~~~
sure.cpp:25:12: warning: unused variable 'val2' [-Wunused-variable]
25 | double val2 = 0;
| ^~~~
sure.cpp:26:9: warning: unused variable 'a' [-Wunused-variable]
26 | int a = 0;
| ^
sure.cpp:27:9: warning: unused variable 'b' [-Wunused-variable]
27 | int b = 0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |