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 ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n;
vector<double>a(n),b(n);
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
}
sort(rall(a));
sort(rall(b));
vector<double>sa(n+1),sb(n+1);
sa[0]=0;
sb[0]=0;
for(int i=0;i<n;i++){
sa[i+1]=sa[i]+a[i];
sb[i+1]=sb[i]+b[i];
}
double ans=0;
for(int i=1;i<=n;i++){
int l=0,r=i;
while(l<r){
int mid=(l+r+1)/2;
if(sa[mid]<=sb[i-mid]){
l=mid;
}
else{
r=mid-1;
}
}
ans=max(ans,sa[l]-i);
if(l<i){
ans=max(ans,sb[i-l-1]-i);
}
}
for(int i=n+1;i<=2*n;i++){
int l=i-n,r=n;
while(l<r){
int mid=(l+r+1)/2;
if(sa[mid]<=sb[i-mid]){
l=mid;
}
else{
r=mid-1;
}
}
ans=max(ans,sa[l]-i);
if(l<n){
ans=max(ans,sb[i-l-1]-i);
}
}
printf("%.4f",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... |