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"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define ordered_mset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double INF = 1e4;
int binpow (int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow (a, n-1) * a;
else {
int b = binpow (a, n/2);
return b * b;
}
}
void solve(){
int n;
cin >> n;
double a[n],b[n];
for(int i = 0;i < n;i++){
cin >> a[i] >> b[i];
}
sort(a,a + n);
sort(b,b + n);
reverse(a,a + n);
reverse(b,b + n);
double prefa[n + 1];
prefa[0] = 0;
double prefb[n + 1];
prefb[0] = 0;
for(int i = 0;i < n;i++){
prefa[i + 1] = prefa[i] + a[i];
prefb[i + 1] = prefb[i] + b[i];
}
double ans = 0;
for(int i = 1;i <= n;i++){
int l = 1,r = n,res = n;
while(l <= r){
int mid = (r + l) >> 1;
int cnt = i + mid;
if(prefa[i] - (cnt) <= prefb[i] - cnt){
res = mid;
r = mid - 1;
} else{
l = mid + 1;
}
}
int cnt = i + res;
ans = max(ans,min(prefa[i] - cnt,prefb[res] - cnt));
if(res != 1){
res--;
}
cnt = i + res;
ans = max(ans,min(prefa[i] - cnt,prefb[res] - cnt));
if(res != 1){
res++;
}
if(res != n){
res++;
}
cnt = i + res;
ans = max(ans,min(prefa[i] - cnt,prefb[res] - cnt));
}
cout << fixed << setprecision(4);
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int 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... |