#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=1e6+5;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
optimise;
int n;
cin>>n;
pair<double,double> tab[n+1];
multiset<pair<double,double>> a;
multiset<pair<double,double>> b;
double cnta=0;
double cntb=0;
for (int i = 1; i <= n; ++i)
{
cin>>tab[i].fi>>tab[i].se;
cnta+=tab[i].fi;
cntb+=tab[i].se;
a.insert({tab[i].fi,tab[i].se});
b.insert({tab[i].se,tab[i].fi});
}
pair<double,double> cur={0,0};
double ans=0;
while(!a.empty()){
if(cur.fi<cur.se){
cur.fi--;
cur.se--;
cur.fi+=a.rbegin()->fi;
cnta-=a.rbegin()->fi;
cntb-=a.rbegin()->se;
b.erase(b.find({a.rbegin()->se,a.rbegin()->fi}));
a.erase(a.find(*a.rbegin()));
}else if(cur.se<cur.fi){
cur.fi--;
cur.se--;
cur.se+=b.rbegin()->fi;
cnta-=b.rbegin()->se;
cntb-=b.rbegin()->fi;
a.erase(a.find({b.rbegin()->se,b.rbegin()->fi}));
b.erase(b.find(*b.rbegin()));
}else if(cnta<cntb){
cur.fi--;
cur.se--;
cur.fi+=a.rbegin()->fi;
cnta-=a.rbegin()->fi;
cntb-=a.rbegin()->se;
b.erase(b.find({a.rbegin()->se,a.rbegin()->fi}));
a.erase(a.find(*a.rbegin()));
}else{
cur.fi--;
cur.se--;
cur.se+=b.rbegin()->fi;
cnta-=b.rbegin()->se;
cntb-=b.rbegin()->fi;
a.erase(a.find({b.rbegin()->se,b.rbegin()->fi}));
b.erase(b.find(*b.rbegin()));
}
ans=max(ans,min(cur.fi,cur.se));
}
cout <<fixed<<setprecision(4)<< ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |