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;
#define int long long
signed main(){
int n; cin>>n;
vector<double> a(n),b(n);
for (int i=0; i<n; i++) cin>>a[i]>>b[i];
sort(a.begin(),a.end(),greater<double>());
sort(b.begin(),b.end(),greater<double>());
//now take prefix sums
for (int i=1; i<n; i++){
a[i]=a[i-1]+a[i];
}
for (int i=1; i<n; i++){
b[i]=b[i-1]+b[i];
}
double ans=0;
int r=0;
for (int i=0; i<n; i++){
while (r<n and b[r]<a[i]) r++;
if (r>=n) break;
ans=max(ans, a[i]-(i+1+r+1));
}
r=0;
for (int i=0; i<n; i++){
while (r<n and a[r]<b[i]) r++;
if (r>=n) break;
ans=max(ans, b[i]-(i+1+r+1));
}
printf("%.4lf",(double)ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |