#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define optimus_prime ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fxd(x) fixed << setprecision(x)
#define all(a) (a.begin() , a.end())
#define popcount(x) __builtin_popcount(x)
#define lwb lower_bound
#define upb upper_bound
#define dl long double
#define ll long long
#define pb push_back
#define sz() size()
#define F first
#define S second
using namespace std;
const ll N = 2e5+9;
ll n;
dl a[N] , b[N] , sum , ans , pref[N];
void solve(){
cin >> n;
for (int i = 1 ; i <= n ; i++)cin >> a[i] >> b[i];
sort (a+1 , a+1+n);
sort (b+1 , b+1+n);
reverse (a+1 , a+1+n);
reverse (b+1 , b+1+n);
for (int i = 1 ; i <= n ; i++)pref[i]=pref[i-1]+b[i];
for (int i = 1 ; i <= n ; i++){
sum+=a[i];
ll l=1 , r=n , res=0;
while (l<=r){
ll md=(l+r)>>1;
if (pref[md]>=sum)r=md-1 , res=md;
else l=md+1;
}
ans=max(ans , sum-i-res);
}
cout << fxd(4) << ans;
}
signed main() {
optimus_prime;
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |