//version1
#include<bits/stdc++.h>
using namespace std;
typedef pair< int ,int > pii;
typedef long double ld;
#define points first
#define time second
bool paradox( vector< vector< pii>> & w, ld c) {
ld time_total = 0 ;
for ( auto group : w) for ( pii p : group)
time_total + = p.time ;
ld time_so_far = 0 ;
vector< pair< int ,pair< ld,ld>>> all;
for ( vector< pii> & group : w) {
ld time_this_group = 0 ;
for ( pii & p : group)
time_this_group + = p.time ;
for ( pii & p : group) {
ld small = p.points * ( 1 - c * ( time_so_far + time_this_group) / time_total) ;
ld big = p.points * ( 1 - c * ( time_so_far + p.time ) / time_total) ;
all.push_back ( make_pair( p.points , make_pair( small, big) ) ) ;
}
time_so_far + = time_this_group;
}
sort( all.begin ( ) , all.end ( ) ) ;
ld max_so_far = - 1 ;
for ( int i = 0 ; i < ( int ) all.size ( ) ; ++ i) {
int j = i;
while ( j + 1 < ( int ) all.size ( ) && all[ j+ 1 ] .first == all[ i] .first )
++ j;
for ( int k = i; k <= j; ++ k)
if ( all[ k] .second .first < max_so_far)
return true ; // paradox
for ( int k = i; k <= j; ++ k)
max_so_far = max( max_so_far, all[ k] .second .second ) ;
i = j;
}
return false ;
}
int cmp( const pii & a, const pii & b) { // -1, 0 or 1
long long tmp = ( long long ) a.first * b.second - ( long long ) a.second * b.first ;
if ( tmp > 0 ) return - 1 ;
if ( tmp == 0 ) return 0 ;
return 1 ;
}
bool sort_cmp( const pii & a, const pii & b) {
int memo = cmp( a, b) ;
return memo == - 1 || ( memo == 0 && a.points < b.points ) ;
}
const int nax = 1e6 + 5 ;
pii in[ nax] ;
int main( ) {
int n;
scanf ( "%d" , & n) ;
for ( int i = 0 ; i < n; ++ i)
scanf ( "%d" , & in[ i] .points ) ;
for ( int i = 0 ; i < n; ++ i)
scanf ( "%d" , & in[ i] .time ) ;
sort( in, in + n, sort_cmp) ;
vector< vector< pii>> w;
for ( int i = 0 ; i < n; ++ i) {
if ( i == 0 || cmp( in[ i- 1 ] , in[ i] ) ! = 0 )
w.push_back ( vector< pii> { } ) ;
w.back ( ) .push_back ( in[ i] ) ;
}
ld low = 0 , high = 1 ;
for ( int rep = 0 ; rep < 40 ; ++ rep) {
ld mid = ( low + high) / 2 ;
if ( paradox( w, mid) ) high = mid;
else low = mid;
}
printf ( "%.10lf\n " , ( double ) ( low + high) / 2 ) ;
return 0 ;
}
// version2
#include <bits/stdc++.h>
using namespace std;
int n;
pair < long long ,long long > tab[ 1000007 ] ;
vector < int > dos1, dos2;
int k;
int scale[ 1000007 ] ;
double maxi[ 1000007 ] ;
double mini[ 1000007 ] ;
double bsa, bsb= 1.0 , bss;
long long sum[ 1000007 ] ;
int it;
int czy;
bool mniej( pair < long long ,long long > a, pair < long long ,long long > b)
{
return a.first * b.second > b.first * a.second ;
}
long long que( int a, int b)
{
return sum[ b] - sum[ a- 1 ] ;
}
int main( )
{
scanf ( "%d" , & n) ;
for ( int i= 1 ; i<= n; i++ )
{
scanf ( "%lld" , & tab[ i] .first ) ;
}
for ( int i= 1 ; i<= n; i++ )
{
scanf ( "%lld" , & tab[ i] .second ) ;
}
sort( tab+ 1 , tab+ 1 + n, mniej) ;
for ( int i= 1 ; i<= n; i++ )
{
dos2.push_back ( tab[ i] .first ) ;
}
sort( dos2.begin ( ) , dos2.end ( ) ) ;
for ( int i= 0 ; i< n; i++ )
{
if ( ! i || dos2[ i] ! = dos2[ i- 1 ] )
{
dos1.push_back ( dos2[ i] ) ;
}
}
k= dos1.size ( ) ;
for ( int i= 1 ; i<= n; i++ )
{
scale[ i] = lower_bound( dos1.begin ( ) , dos1.end ( ) , tab[ i] .first ) - dos1.begin ( ) + 1 ;
}
for ( int i= 1 ; i<= n; i++ )
{
sum[ i] = sum[ i- 1 ] + tab[ i] .second ;
}
for ( int h= 1 ; h<= 100 ; h++ )
{
bss= ( bsa+ bsb) / 2.0 ;
for ( int i= 1 ; i<= k; i++ )
{
mini[ i] = 1000000000.0 ;
maxi[ i] = 0.0 ;
}
it= 0 ;
for ( int i= 1 ; i<= n; i++ )
{
while ( it+ 1 < i && mniej( tab[ it+ 1 ] , tab[ i] ) )
it++ ;
maxi[ scale[ i] ] = max( maxi[ scale[ i] ] , tab[ i] .first * ( 1.0 - bss* ( que( 1 , it) + tab[ i] .second ) / sum[ n] ) ) ;
}
it= n+ 1 ;
for ( int i= n; i; i-- )
{
while ( it- 1 > i && mniej( tab[ i] , tab[ it- 1 ] ) )
it-- ;
mini[ scale[ i] ] = min( mini[ scale[ i] ] , tab[ i] .first * ( 1.0 - bss* que( 1 , it- 1 ) / sum[ n] ) ) ;
}
czy= 0 ;
for ( int i= 2 ; i<= k; i++ )
{
if ( mini[ i] < maxi[ i- 1 ] )
{
czy= 1 ;
}
}
if ( czy)
{
bsb= bss;
}
else
{
bsa= bss;
}
}
printf ( "%.11lf\n " , bss) ;
return 0 ;
}
Ly92ZXJzaW9uMQojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIHBhaXI8aW50LGludD4gcGlpOwp0eXBlZGVmIGxvbmcgZG91YmxlIGxkOwojZGVmaW5lIHBvaW50cyBmaXJzdAojZGVmaW5lIHRpbWUgc2Vjb25kCgpib29sIHBhcmFkb3godmVjdG9yPHZlY3RvcjxwaWk+PiAmIHcsIGxkIGMpIHsKCWxkIHRpbWVfdG90YWwgPSAwOwoJZm9yKGF1dG8gZ3JvdXAgOiB3KSBmb3IocGlpIHAgOiBncm91cCkKCQl0aW1lX3RvdGFsICs9IHAudGltZTsKCWxkIHRpbWVfc29fZmFyID0gMDsKCXZlY3RvcjxwYWlyPGludCxwYWlyPGxkLGxkPj4+IGFsbDsKCWZvcih2ZWN0b3I8cGlpPiAmIGdyb3VwIDogdykgewoJCWxkIHRpbWVfdGhpc19ncm91cCA9IDA7CgkJZm9yKHBpaSAmIHAgOiBncm91cCkKCQkJdGltZV90aGlzX2dyb3VwICs9IHAudGltZTsKCQlmb3IocGlpICYgcCA6IGdyb3VwKSB7CgkJCWxkIHNtYWxsID0gc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GRvczJbaV0pOwogICAgICAgIH0KICAgIH0KICAgIGs9ZG9zMS5zaXplKCk7CiAgICBmb3IgKGludCBpPTE7IGk8PW47IGkrKykKICAgIHsKICAgICAgICBzY2FsZVtpXT1sb3dlcl9ib3VuZChkb3MxLmJlZ2luKCksIGRvczEuZW5kKCksIHRhYltpXS5maXJzdCktZG9zMS5iZWdpbigpKzE7CiAgICB9CiAgICBmb3IgKGludCBpPTE7IGk8PW47IGkrKykKICAgIHsKICAgICAgICBzdW1baV09c3VtW2ktMV0rdGFiW2ldLnNlY29uZDsKICAgIH0KICAgIGZvciAoaW50IGg9MTsgaDw9MTAwOyBoKyspCiAgICB7CiAgICAgICAgYnNzPShic2ErYnNiKS8yLjA7CiAgICAgICAgZm9yIChpbnQgaT0xOyBpPD1rOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBtaW5pW2ldPTEwMDAwMDAwMDAuMDsKICAgICAgICAgICAgbWF4aVtpXT0wLjA7CiAgICAgICAgfQogICAgICAgIGl0PTA7CiAgICAgICAgZm9yIChpbnQgaT0xOyBpPD1uOyBpKyspCiAgICAgICAgewogICAgICAgICAgICB3aGlsZShpdCsxPGkgJiYgbW5pZWoodGFiW2l0KzFdLCB0YWJbaV0pKQogICAgICAgICAgICBpdCsrOwogICAgICAgICAgICBtYXhpW3NjYWxlW2ldXT1tYXgobWF4aVtzY2FsZVtpXV0sIHRhYltpXS5maXJzdCooMS4wLWJzcyoocXVlKDEsIGl0KSt0YWJbaV0uc2Vjb25kKS9zdW1bbl0pKTsKICAgICAgICB9CiAgICAgICAgaXQ9bisxOwogICAgICAgIGZvciAoaW50IGk9bjsgaTsgaS0tKQogICAgICAgIHsKICAgICAgICAgICAgd2hpbGUoaXQtMT5pICYmIG1uaWVqKHRhYltpXSwgdGFiW2l0LTFdKSkKICAgICAgICAgICAgaXQtLTsKICAgICAgICAgICAgbWluaVtzY2FsZVtpXV09bWluKG1pbmlbc2NhbGVbaV1dLCB0YWJbaV0uZmlyc3QqKDEuMC1ic3MqcXVlKDEsIGl0LTEpL3N1bVtuXSkpOwogICAgICAgIH0KICAgICAgICBjenk9MDsKICAgICAgICBmb3IgKGludCBpPTI7IGk8PWs7IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGlmIChtaW5pW2ldPG1heGlbaS0xXSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY3p5PTE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGN6eSkKICAgICAgICB7CiAgICAgICAgICAgIGJzYj1ic3M7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGJzYT1ic3M7CiAgICAgICAgfQogICAgfQogICAgcHJpbnRmKCIlLjExbGZcbiIsIGJzcyk7CiAgICByZXR1cm4gMDsKfQ==