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 <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(4);
int n; cin >> n;
double a[n], b[n];
for (int i = 0; i < n; i++){
cin >> a[i] >> b[i];
}
sort(a, a + n, greater<double>());
sort(b, b + n, greater<double>());
double prefa[n + 1]{}, prefb[n + 1]{};
for (int i = 0; i < n; i++){
prefa[i + 1] = prefa[i] + a[i];
prefb[i + 1] = prefb[i] + b[i];
}
double ans = 0;
int pa = 0, pb = 0;
while (pa <= n && pb <= n){
if (prefa[pa] < prefb[pb])
pa++;
else
pb++;
ans = max(ans, min(prefa[pa], prefb[pb]) - pa - pb);
}
while (pa <= n){
pa++;
ans = max(ans, min(prefa[pa], prefb[pb]) - pa - pb);
}
while (pb <= n){
pb++;
ans = max(ans, min(prefa[pa], prefb[pb]) - pa - pb);
}
cout << ans << '\n';
return 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... |