This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define pll2 pair<pll,ll>
#define bit(i,k) ((k>>i)&1)
#define pii pair<int,int>
using namespace std;
const long long mod = 998244353;
const ll inf = 1e18;
const ll maxN=1e5+5;
ld a[maxN],b[maxN];
bool cmp(ld a,ld b){
return a>b;
}
ld pfs1[maxN],pfs2[maxN];
void solve(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
}
sort(a+1,a+n+1,cmp);
sort(b+1,b+n+1,cmp);
for(int i=1;i<=n;i++){
pfs1[i]=pfs1[i-1]+a[i];
pfs2[i]=pfs2[i-1]+b[i];
}
ld ans=0;
for(int i=0;i<=n;i++){
ll res=0;
ll l=0,r=n;
ll target=n+1;
while(l<=r){
ll md=(l+r)/2;
if(pfs2[md]<pfs1[i]){
l=md+1;
target=md;
}
else{
r=md-1;
}
}
if(target<=n){
ans=max(ans,min(pfs1[i],pfs2[target])-i-target);
}
target++;
if(target<=n){
ans=max(ans,min(pfs1[i],pfs2[target])-i-target);
}
}
cout<<setprecision(4)<<fixed<<ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("lottery.inp", "r", stdin);
// freopen("lottery.out", "w", stdout);
ll nhim = 1;
// cin >> nhim;
// cout<<nhim<<'\n';
while (nhim--) {
solve();
}
}
Compilation message (stderr)
sure.cpp: In function 'void solve()':
sure.cpp:42:8: warning: unused variable 'res' [-Wunused-variable]
42 | ll res=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... |