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 pb push_back
#define deb(x) cout<<#x<<": "<<x<<endl;
using lli=long long int;
using ld=long double;
void solve(){
lli n=1;
// deb(n);
cin>>n;
// deb(n);
vector<ld> v1(n);
vector<ld> v2(n);
for(lli i=0; i<n; ++i){
cin>>v1[i]>>v2[i];
// deb(v1[i]);
// deb(v2[i]);
}
sort(v1.rbegin(), v1.rend());
sort(v2.rbegin(), v2.rend());
ld ans=0;
vector<ld> v3=v2;
v3[0]--;
for(lli i=1; i<n; ++i){
v3[i]+=v3[i-1]-1;
}
for(lli i=1; i<n; ++i){
v3[i]=max(v3[i],v3[i-1]);
// deb(v3[i]);
}
ld sum1=0;
ld sum2=0;
lli j=0;
for(lli i=0; i<n ; ++i){
sum1+=v1[i];
while(j<n && sum2<sum1){
sum2+=v2[j];
j++;
}
ld aux;
if(j>=2){
aux=v3[j-2]-i-1;
}
else aux=0;
// deb(j);
// deb(sum1);
// deb(sum2);
//deb(aux);
aux=max(aux, sum1-i-1-j);
ans=max(ans, aux);
}
cout<<setprecision(5)<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
lli t=1;
//cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |