using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var a = sc.Long(n);
            var b = sc.Long(n);
            var T = b.Sum();
            //得点は昇順を仮定する
            Array.Sort(a, b);
            var last = new bool[n];
            for (int i = 1; i < n; i++)
                if (a[i - 1] < a[i]) last[i - 1] = true;

            var mint = new long[n];
            var maxt = new long[n];
            var id = Enumerate(n, x => x);
            //コスパの良い方から解く．同じ場合は得点が低い方から解くことにする
            Array.Sort(id, (l, r) =>
            {
                var cmp = (a[r] * b[l]).CompareTo(a[l] * b[r]);
                if (cmp != 0) return cmp;
                else return a[l].CompareTo(a[r]);
            });
            var na = Enumerate(n, x => a[id[x]]);
            var nb = Enumerate(n, x => b[id[x]]);
            //for (int i = 0; i < n; i++) Debug.WriteLine("{0} {1} {2}", na[i], nb[i], 1.0 * na[i] / nb[i]);
            var t = 0L;
            for (int l = 0; l < n;)
            {
                var r = l;
                var s = t;
                while (r < n && na[r] * nb[l] == na[l] * nb[r]) r++;
                for (int i = l; i < r; i++)
                    t += nb[i];
                for (int i = l; i < r; i++)
                {
                    mint[id[i]] = s + nb[i];
                    maxt[id[i]] = t;
                }
                l = r;
            }
            for (int i = 0; i < n; i++)
                Debug.WriteLine("{0} {1} {2} {3} {4}", a[i], b[i], 1.0 * a[i] / b[i], mint[i], maxt[i]);
            {
                var l = 0.0;
                var r = 1.0;
                var vmin = new double[n];
                var vmax = new double[n];
                for (int _ = 0; _ < 100; _++)
                {
                    var m = (l + r) / 2;
                    for (int i = 0; i < n; i++)
                    {
                        vmin[i] = a[i] * (1 - maxt[i] * m / T);
                        vmax[i] = a[i] * (1 - mint[i] * m / T);
                    }
                    var ok = true;
                    var v = -1.0;
                    var u = -1.0;
                    //Debug.WriteLine(vmin.AsJoinedString());
                    //Debug.WriteLine(vmax.AsJoinedString());

                    for (int i = 0; i < n; i++)
                    {
                        if (v > vmin[i])
                            ok = false;
                        u = Math.Max(u, vmax[i]);
                        if (last[i]) v = Math.Max(v, u);
                    }
                    if (ok) l = m;
                    else r = m;
                }

                IO.Printer.Out.WriteLine(l);
            }
        }

        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}
#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var a = sc.Long(n);
            var b = sc.Long(n);
            var T = b.Sum();
            //得点は昇順を仮定する
            Array.Sort(a, b);
            var last = new bool[n];
            for (int i = 1; i < n; i++)
                if (a[i - 1] < a[i]) last[i] = true;

            var mint = new long[n];
            var maxt = new long[n];
            var id = Enumerate(n, x => x);
            //コスパの良い方から解く．同じ場合は得点が低い方から解くことにする
            Array.Sort(id, (l, r) =>
            {
                var cmp = (a[r] * b[l]).CompareTo(a[l] * b[r]);
                if (cmp != 0) return cmp;
                else return a[l].CompareTo(a[r]);
            });
            var na = Enumerate(n, x => a[id[x]]);
            var nb = Enumerate(n, x => b[id[x]]);
            for (int i = 0; i < n; i++)
                Debug.WriteLine("{0} {1} {2}", na[i], nb[i], 1.0 * na[i] / nb[i]);
            var t = 0L;
            for (int l = 0; l < n;)
            {
                var r = l;
                var s = t;
                while (r < n && na[r] * nb[l] == na[l] * nb[r]) r++;
                for (int i = l; i < r; i++)
                    t += nb[i];
                for (int i = l; i < r; i++)
                {
                    mint[id[i]] = s + nb[i];
                    maxt[id[i]] = t;
                }
                l = r;
            }
            {
                var l = 0.0;
                var r = 1.0;
                var vmin = new double[n];
                var vmax = new double[n];
                for (int _ = 0; _ < 100; _++)
                {
                    var m = (l + r) / 2;
                    for (int i = 0; i < n; i++)
                    {
                        vmin[i] = a[i] * (1 - maxt[i] * m / T);
                        vmax[i] = a[i] * (1 - mint[i] * m / T);
                    }
                    var ok = true;
                    var v = -1.0;
                    var u = -1.0;

                    for (int i = 0; i < n; i++)
                    {
                        if (v > vmin[i]) ok = false;
                        u = Math.Max(u, vmax[i]);
                        if (last[i]) v = Math.Max(v, u);
                    }
                    if (ok) l = m;
                    else r = m;
                }

                IO.Printer.Out.WriteLine(l);
            }
        }

        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}
#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var a = sc.Long(n);
            var b = sc.Long(n);
            var T = b.Sum();
            //得点は昇順を仮定する
            Array.Sort(a, b);

            var mint = new long[n];
            var maxt = new long[n];
            var id = Enumerate(n, x => x);
            //コスパの良い方から解く．同じ場合は得点が低い方から解くことにする
            Array.Sort(id, (l, r) =>
            {
                var cmp = (a[r] * b[l]).CompareTo(a[l] * b[r]);
                if (cmp != 0) return cmp;
                else return a[l].CompareTo(a[r]);
            });
            var na = Enumerate(n, x => a[id[x]]);
            var nb = Enumerate(n, x => b[id[x]]);
            for (int i = 0; i < n; i++)
                Debug.WriteLine("{0} {1} {2}", na[i], nb[i], 1.0 * na[i] / nb[i]);
            var t = 0L;
            for (int l = 0; l < n;)
            {
                var r = l;
                var s = t;
                while (r < n && na[r] * nb[l] == na[l] * nb[r]) r++;
                for (int i = l; i < r; i++)
                    t += nb[i];
                for (int i = l; i < r; i++)
                {
                    mint[id[i]] = s + nb[i];
                    maxt[id[i]] = t;
                }
                l = r;
            }
            {
                var l = 0.0;
                var r = 1.0;
                var vmin = new double[n];
                var vmax = new double[n];
                for (int _ = 0; _ < 100; _++)
                {
                    var m = (l + r) / 2;
                    for (int i = 0; i < n; i++)
                    {
                        vmin[i] = a[i] * (1 - maxt[i] * m / T);
                        vmax[i] = a[i] * (1 - mint[i] * m / T);
                    }
                    var ok = true;
                    var v = -1.0;
                    for (int i = 0; i < n; i++)
                    {
                        if (v > vmin[i]) ok = false;
                        v = Math.Max(v, vmax[i]);
                    }
                    if (ok) l = m;
                    else r = m;
                }

                IO.Printer.Out.WriteLine(l);
            }
        }

        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}
#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class D {

    private static final double EPS = 1e-9;

    private void solve() throws IOException {
        int n = nextInt();
        Problem[] problems = new Problem[n];
        for (int i = 0; i < n; i++) {
            problems[i] = new Problem();
        }
        for (int i = 0; i < n; i++) {
            problems[i].p = nextInt();
        }
        for (int i = 0; i < n; i++) {
            problems[i].t = nextInt();
        }

        Arrays.sort(problems);

        int l = 0;
        long tt = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n) {
                long d = problems[r].p * problems[l].t - problems[l].p * problems[r].t;
                if (d != 0) break;
                r++;
            }

            for (int i = l; i < r; i++) {
                problems[i].minTime = tt + problems[i].t;
            }

            for (int i = l; i < r; i++) {
                tt += problems[i].t;
            }

            for (int i = l; i < r; i++) {
                problems[i].maxTime = tt;
            }

            l = r;
        }

        Arrays.sort(problems, new Comparator<Problem>() {
            @Override
            public int compare(Problem o1, Problem o2) {
                return Long.compare(o1.p, o2.p);
            }
        });

//        for (Problem problem : problems) {
//            System.out.println(problem.p + " " +problem.t + " " +problem.minTime + " " + problem.maxTime);
//        }

        double[] x = new double[n + 2];
        double[] y = new double[n + 2];
        int m = 2;
        x[0] = 1;
        x[1] = 0;
        double[] aa = new double[n + 2];
        double[] bb = new double[n + 2];

        double res = 1;

        l = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n && problems[r].p == problems[l].p) {
                r++;
            }
            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].maxTime / tt;
                int ll = -1;
                int rr = m;
                while (rr > ll + 1) {
                    int mm = (ll + rr) / 2;
                    double v = a * x[mm] + b;
                    if (v < y[mm] - EPS) {
                        ll = mm;
                    } else {
                        rr = mm;
                    }
                }

//                System.out.println(a + " " + b);
//                System.out.println(problems[i].p + " " + problems[i].t + " " + ll);

                if (ll == -1) {
                    continue;
                }
                if (rr == m) {
                    res = 0;
                    continue;
                }

                double xx = (bb[ll] - b) / (a - aa[ll]);

//                System.out.println(problems[i].p + " " + problems[i].t + " " + xx);

                if (Double.isNaN(xx)) continue;
                res = Math.min(res, xx);
            }

            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].minTime / tt;
                while (m > 0 && y[m - 1] < a * x[m - 1] + b + EPS) {
                    m--;
                }
                if (m == 0) {
                    x[0] = 1;
                    y[0] = a + b;
                    aa[0] = a;
                    bb[0] = b;
                    m++;
                } else {
                    double xx = (bb[m - 1] - b) / (a - aa[m - 1]);
                    double yy = a * xx + b;
                    x[m] = xx;
                    y[m] = yy;
                    aa[m] = a;
                    bb[m] = b;
                    m++;
                }
                x[m] = 0;
                y[m] = b;
                m++;

            }

//            for (int i = 0; i < m; i++) {
//                System.out.println("(" + x[i] + " " + y[i] + " " + aa[i] + " " + bb[i] + ")");
//            }

            l = r;
        }

        out.println(res);
    }

    class Problem implements Comparable<Problem> {
        long t, p;
        long minTime, maxTime;

        @Override
        public int compareTo(Problem o) {
            long d = o.p * t - p * o.t;
            if (d != 0) {
                return Long.signum(d);
            } else {
                return Long.compare(p, o.p);
            }
        }
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new D().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class D {

    private static final double EPS = 1e-9;

    private void solve() throws IOException {
        int n = nextInt();
        Problem[] problems = new Problem[n];
        for (int i = 0; i < n; i++) {
            problems[i] = new Problem();
        }
        for (int i = 0; i < n; i++) {
            problems[i].p = nextInt();
        }
        for (int i = 0; i < n; i++) {
            problems[i].t = nextInt();
        }

        Arrays.sort(problems);

        int l = 0;
        long tt = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n) {
                long d = problems[r].p * problems[l].t - problems[l].p * problems[r].t;
                if (d != 0) break;
                r++;
            }

            for (int i = l; i < r; i++) {
                problems[i].minTime = tt + problems[i].t;
            }

            for (int i = l; i < r; i++) {
                tt += problems[i].t;
            }

            for (int i = l; i < r; i++) {
                problems[i].maxTime = tt;
            }

            l = r;
        }

        Arrays.sort(problems, new Comparator<Problem>() {
            @Override
            public int compare(Problem o1, Problem o2) {
                return Long.compare(o1.p, o2.p);
            }
        });

//        for (Problem problem : problems) {
//            System.out.println(problem.p + " " +problem.t + " " +problem.minTime + " " + problem.maxTime);
//        }

        double[] x = new double[2 * n + 2];
        double[] y = new double[2 * n + 2];
        int m = 2;
        x[0] = 1;
        x[1] = 0;
        double[] aa = new double[2 * n + 2];
        double[] bb = new double[2 * n + 2];

        double res = 1;

        l = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n && problems[r].p == problems[l].p) {
                r++;
            }
            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].maxTime / tt;
                int ll = -1;
                int rr = m;
                while (rr > ll + 1) {
                    int mm = (ll + rr) / 2;
                    double v = a * x[mm] + b;
                    if (v < y[mm] - EPS) {
                        ll = mm;
                    } else {
                        rr = mm;
                    }
                }

//                System.out.println(a + " " + b);
//                System.out.println(problems[i].p + " " + problems[i].t + " " + ll);

                if (ll == -1) {
                    continue;
                }
                if (rr == m) {
                    res = 0;
                    continue;
                }

                double xx = (bb[ll] - b) / (a - aa[ll]);

                if (xx < 0) xx = 0;
                if (xx > 1) xx = 1;

//                System.out.println(problems[i].p + " " + problems[i].t + " " + xx);

                if (Double.isNaN(xx)) continue;
                res = Math.min(res, xx);
            }

            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].minTime / tt;
                while (m > 0 && y[m - 1] < a * x[m - 1] + b + EPS) {
                    m--;
                }
                if (m == 0) {
                    x[0] = 1;
                    y[0] = a + b;
                    aa[0] = a;
                    bb[0] = b;
                    m++;
                } else {
                    double xx = (bb[m - 1] - b) / (a - aa[m - 1]);
                    double yy = a * xx + b;

                    if (xx < 0) xx = 0;
                    if (xx > 1) xx = 1;

                    x[m] = xx;
                    y[m] = yy;
                    aa[m] = a;
                    bb[m] = b;
                    m++;
                }
                x[m] = 0;
                y[m] = b;
                m++;

            }

//            for (int i = 0; i < m; i++) {
//                System.out.println("(" + x[i] + " " + y[i] + " " + aa[i] + " " + bb[i] + ")");
//            }

            l = r;
        }

        out.println(res);
    }

    class Problem implements Comparable<Problem> {
        long t, p;
        long minTime, maxTime;

        @Override
        public int compareTo(Problem o) {
            long d = o.p * t - p * o.t;
            if (d != 0) {
                return Long.signum(d);
            } else {
                return Long.compare(p, o.p);
            }
        }
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new D().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class D {

    private static final double EPS = 1e-9;

    private void solve() throws IOException {
        int n = nextInt();
        Problem[] problems = new Problem[n];
        for (int i = 0; i < n; i++) {
            problems[i] = new Problem();
        }
        for (int i = 0; i < n; i++) {
            problems[i].p = nextInt();
        }
        for (int i = 0; i < n; i++) {
            problems[i].t = nextInt();
        }

        Arrays.sort(problems);

        int l = 0;
        long tt = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n) {
                long d = problems[r].p * problems[l].t - problems[l].p * problems[r].t;
                if (d != 0) break;
                r++;
            }

            for (int i = l; i < r; i++) {
                problems[i].minTime = tt + problems[i].t;
            }

            for (int i = l; i < r; i++) {
                tt += problems[i].t;
            }

            for (int i = l; i < r; i++) {
                problems[i].maxTime = tt;
            }

            l = r;
        }

        Arrays.sort(problems, new Comparator<Problem>() {
            @Override
            public int compare(Problem o1, Problem o2) {
                return Long.compare(o1.p, o2.p);
            }
        });

//        for (Problem problem : problems) {
//            System.out.println(problem.p + " " +problem.t + " " +problem.minTime + " " + problem.maxTime);
//        }

        double[] x = new double[n + 2];
        double[] y = new double[n + 2];
        int m = 2;
        x[0] = 1;
        x[1] = 0;
        double[] aa = new double[n + 2];
        double[] bb = new double[n + 2];

        double res = 1;

        l = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n && problems[r].p == problems[l].p) {
                r++;
            }
            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].maxTime / tt;
                int ll = -1;
                int rr = m;
                while (rr > ll + 1) {
                    int mm = (ll + rr) / 2;
                    double v = a * x[mm] + b;
                    if (v < y[mm] - EPS) {
                        ll = mm;
                    } else {
                        rr = mm;
                    }
                }

//                System.out.println(a + " " + b);
//                System.out.println(problems[i].p + " " + problems[i].t + " " + ll);

                if (ll == -1) {
                    continue;
                }
                if (rr == m) {
                    res = 0;
                    continue;
                }

                double xx = (bb[ll] - b) / (a - aa[ll]);

                if (xx < 0) xx = 0;
                if (xx > 1) xx = 1;

//                System.out.println(problems[i].p + " " + problems[i].t + " " + xx);

                if (Double.isNaN(xx)) continue;
                res = Math.min(res, xx);
            }

            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].minTime / tt;
                while (m > 0 && y[m - 1] < a * x[m - 1] + b + EPS) {
                    m--;
                }
                if (m == 0) {
                    x[0] = 1;
                    y[0] = a + b;
                    aa[0] = a;
                    bb[0] = b;
                    m++;
                } else {
                    double xx = (bb[m - 1] - b) / (a - aa[m - 1]);
                    double yy = a * xx + b;

                    if (xx < 0) xx = 0;
                    if (xx > 1) xx = 1;

                    x[m] = xx;
                    y[m] = yy;
                    aa[m] = a;
                    bb[m] = b;
                    m++;
                }
                x[m] = 0;
                y[m] = b;
                m++;

            }

//            for (int i = 0; i < m; i++) {
//                System.out.println("(" + x[i] + " " + y[i] + " " + aa[i] + " " + bb[i] + ")");
//            }

            l = r;
        }

        out.println(res);
    }

    class Problem implements Comparable<Problem> {
        long t, p;
        long minTime, maxTime;

        @Override
        public int compareTo(Problem o) {
            long d = o.p * t - p * o.t;
            if (d != 0) {
                return Long.signum(d);
            } else {
                return Long.compare(p, o.p);
            }
        }
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new D().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class D {

    private static final double EPS = 1e-12;

    private void solve() throws IOException {
        int n = nextInt();
        Problem[] problems = new Problem[n];
        for (int i = 0; i < n; i++) {
            problems[i] = new Problem();
        }
        for (int i = 0; i < n; i++) {
            problems[i].p = nextInt();
        }
        for (int i = 0; i < n; i++) {
            problems[i].t = nextInt();
        }

        Arrays.sort(problems);

        int l = 0;
        long tt = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n) {
                long d = problems[r].p * problems[l].t - problems[l].p * problems[r].t;
                if (d != 0) break;
                r++;
            }

            for (int i = l; i < r; i++) {
                problems[i].minTime = tt + problems[i].t;
            }

            for (int i = l; i < r; i++) {
                tt += problems[i].t;
            }

            for (int i = l; i < r; i++) {
                problems[i].maxTime = tt;
            }

            l = r;
        }

        Arrays.sort(problems, new Comparator<Problem>() {
            @Override
            public int compare(Problem o1, Problem o2) {
                return Long.compare(o1.p, o2.p);
            }
        });

//        for (Problem problem : problems) {
//            System.out.println(problem.p + " " +problem.t + " " +problem.minTime + " " + problem.maxTime);
//        }

        double[] x = new double[n + 2];
        double[] y = new double[n + 2];
        int m = 2;
        x[0] = 1;
        x[1] = 0;
        double[] aa = new double[n + 2];
        double[] bb = new double[n + 2];

        double res = 1;

        l = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n && problems[r].p == problems[l].p) {
                r++;
            }
            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].maxTime / tt;
                int ll = -1;
                int rr = m;
                while (rr > ll + 1) {
                    int mm = (ll + rr) / 2;
                    double v = a * x[mm] + b;
                    if (v < y[mm] - EPS) {
                        ll = mm;
                    } else {
                        rr = mm;
                    }
                }

//                System.out.println(a + " " + b);
//                System.out.println(problems[i].p + " " + problems[i].t + " " + ll);

                if (ll == -1) {
                    continue;
                }
                if (rr == m) {
                    res = 0;
                    continue;
                }

                double xx = (bb[ll] - b) / (a - aa[ll]);

//                System.out.println(problems[i].p + " " + problems[i].t + " " + xx);

                if (Double.isNaN(xx)) continue;
                res = Math.min(res, xx);
            }

            for (int i = l; i < r; i++) {
                double b = problems[i].p;
                double a = -1.0 * problems[i].p * problems[i].minTime / tt;
                while (m > 0 && y[m - 1] < a * x[m - 1] + b + EPS) {
                    m--;
                }
                if (m == 0) {
                    x[0] = 1;
                    y[0] = a + b;
                    aa[0] = a;
                    bb[0] = b;
                    m++;
                } else {
                    double xx = (bb[m - 1] - b) / (a - aa[m - 1]);
                    double yy = a * xx + b;
                    x[m] = xx;
                    y[m] = yy;
                    aa[m] = a;
                    bb[m] = b;
                    m++;
                }
                x[m] = 0;
                y[m] = b;
                m++;

            }

//            for (int i = 0; i < m; i++) {
//                System.out.println("(" + x[i] + " " + y[i] + " " + aa[i] + " " + bb[i] + ")");
//            }

            l = r;
        }

        out.println(res);
    }

    class Problem implements Comparable<Problem> {
        long t, p;
        long minTime, maxTime;

        @Override
        public int compareTo(Problem o) {
            long d = o.p * t - p * o.t;
            if (d != 0) {
                return Long.signum(d);
            } else {
                return Long.compare(p, o.p);
            }
        }
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new D().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


#include<cstdio>
#include<algorithm>
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define dep(i,x,y) for(int i=(x);i>=(y);i--)
#define N 200000
using namespace std;
int n,x,u,tt[N];long long T,T0,T1,t0[N],t1[N];double l,r,m,P,pt[N];
struct pr{long long p,t;int id;}a[N];
inline bool cmp0(const pr &x,const pr &y){return x.p<y.p;}
inline bool cmp(const pr &x,const pr &y){return x.p*y.t>y.p*x.t;}
int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%I64d",&a[i].p);
	rep(i,1,n)scanf("%I64d",&a[i].t);
	rep(i,1,n)T+=a[i].t;
	sort(a+1,a+n+1,cmp0);rep(i,1,n)a[i].id=i;
	sort(a+1,a+n+1,cmp);rep(i,1,n)tt[a[i].id]=i;
	l=0;r=1;m=0.5;T0=T1=0;
	rep(i,1,n){
		if(a[i].p*a[i-1].t!=a[i-1].p*a[i].t)T0=T1;
		T1+=a[i].t;t0[i]=T0+a[i].t;
	}T0=T1=T;
	dep(i,n,1){
		if(a[i].p*a[i+1].t!=a[i+1].p*a[i].t)T0=T1;
		T1-=a[i].t;t1[i]=T0;
	}
	for(;r-l>1e-12;m=(l+r)/2){
		rep(i,1,n){
			P=a[tt[i]].p*(1-m*t0[tt[i]]/T);
			pt[i]=pt[i-1];if(P>pt[i])pt[i]=P;
		}x=n;u=1;
		dep(i,n,1){
			while(a[tt[x]].p>=a[tt[i]].p)x--;
			P=a[tt[i]].p*(1-m*t1[tt[i]]/T);
			if(P<pt[x]){u=0;break;}
		}
		if(u)l=m;else r=m;
	}
	printf("%.11lf\n",m);
}


#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define pi ((db)3.14159265358979323846264338327950288L)
#define buli __builtin_popcountll
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef long double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
const db eps=1e-6;
int mo=1000000007;
int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}
int n;
struct node{
	int p,t;
}a[222222];
int cmp(const node&a,const node&b){
	return 1ll*a.t*b.p<1ll*b.t*a.p;
}
ll tsu[222222];
int lef[222222],rig[222222];
ll tmi[222222],tma[222222];

db T;
struct pkt{
	int x;
	db y;
}p[444444];
int cmpp(const pkt&a,const pkt&b){
	if(a.x==b.x)return a.y>b.y;
	return a.x<b.x;
}
int ptot=0;
int main()
{
#ifdef JCVB
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int _time_jc=clock();
#endif
	gn(n);
	rep(i,1,n+1){
		gn(a[i].p);
	}
	rep(i,1,n+1){
		gn(a[i].t);
	}
	sort(a+1,a+1+n,cmp);
	tsu[0]=0;
	rep(i,1,n+1)tsu[i]=tsu[i-1]+a[i].t;
	T=tsu[n];
	lef[1]=1;
	rep(i,2,n+1){
		if(!cmp(a[i],a[i-1]) && !cmp(a[i-1],a[i]))lef[i]=lef[i-1];
		else lef[i]=i;
	}
	rig[n]=n;
	per(i,1,n){
		if(!cmp(a[i],a[i+1]) && !cmp(a[i+1],a[i]))rig[i]=rig[i+1];
		else rig[i]=i;
	}

	rep(i,1,n+1){
		tmi[i]=tsu[lef[i]-1]+a[i].t;
		tma[i]=tsu[rig[i]];
	}

	rep(i,1,n+1){
		p[++ptot]=(pkt){a[i].p,db(a[i].p)*tmi[i]};
		p[++ptot]=(pkt){a[i].p,db(a[i].p)*tma[i]};
	}
	sort(p+1,p+1+ptot,cmpp);
	db ma=T;
	rep(i,1,ptot)if(p[i].x!=p[i+1].x){
		upmax(ma,(p[i+1].y-p[i].y)/(p[i+1].x-p[i].x));
	}
	printf("%.10lf\n",double(T/ma));
#ifdef JCVB
	debug("time: %d\n",int(clock()-_time_jc));
#endif
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

const int MaxN = 150010;
const ll inf = 1ll << 60;
struct node {
	int p, t;
	ll l, r;
}	P[MaxN];
int N;
double ans = 1;

bool cmp(const node &a, const node &b) {
	return 1ll * a.t * b.p < 1ll * a.p * b.t;
}
bool cmpP(const node &a, const node &b) {
	return a.p < b.p;
}

double intersect(double b0, double k0, double b1, double k1) {
	return (b0 - b1) / (k1 - k0);
}

int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &P[i].p);
	for (int i = 1; i <= N; ++i) scanf("%d", &P[i].t);
	sort(P + 1, P + N + 1, cmp);
	ll sum = 0;
	for (int i = 1; i <= N; ++i) {
		int j = i;
		ll tsum = P[i].t;
		while ((j < N) && (1ll * P[i].t * P[j + 1].p == 1ll * P[i].p * P[j + 1].t)) {
			++j;
			tsum += P[j].t;
		}
		for (int k = i; k <= j; ++k) {
			P[k].l = sum + P[k].t;
			P[k].r = sum + tsum;
		}
		sum += tsum;
		i = j;
	}
	double T = 1.0 / sum;
	sort(P + 1, P + N + 1, cmpP);
	ll lastl = 0, lastp = 0;
	for (int i = 1; i <= N; ++i) {
		int j = i;
		ll r = 0, l = inf, p = P[i].p;
		while ((j < N) && (P[j + 1].p == P[i].p)) ++j;
		for (int k = i; k <= j; ++k) {
			r = max(r, P[k].r);
			l = min(l, P[k].l);
		}
		if (i > 1) {
			double inter = intersect(lastp, -T * lastl * lastp, p, -T * r * p);
			if (inter > 0) ans = min(ans, inter);
		}
		lastl = l;
		lastp = p;
		i = j;
	}
	printf("%.12lf\n", ans);
	return 0;
}


#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
class Q
{
public:
	ll x, y;
	Q() {}
	Q(ll x, ll y) :x(x), y(y) {}
	bool operator < (Q q)const
	{
		return x*q.y < y*q.x;
	}
	bool operator == (Q q)const
	{
		return x*q.y == y*q.x;
	}
};
typedef long double ld;
typedef pair<ld, ld>pdd;
typedef pair<ll, ll>pii;
typedef pair<ll, ld>pid;
typedef pair<ll, pdd>pidd;
ld eps = 1e-14;
int main()
{
	int num;
	scanf("%d", &num);
	vector<Q>vec;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		vec.push_back(Q(z, 0));
	}
	ll sum = 0;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		vec[i].y = z;
		sum += z;
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	ld mini = 1.0;
	vector<pidd>ans;
	Q now = Q(0, 1);
	vector<Q>zv;
	ll s = 0;
	vec.push_back(Q(-1, 1));
	for (int i = 0; i <= num; i++)
	{
		if (now == vec[i])
		{
			zv.push_back(vec[i]);
		}
		else
		{
			ll zs = 0;
			for (int j = 0; j < zv.size(); j++)zs += zv[j].y;
			for (int j = 0; j < zv.size(); j++)
			{
				ans.push_back(make_pair(zv[j].x, make_pair(ld(s + zs)*ld(zv[j].x) / ld(sum), ld(s + zv[j].y)*ld(zv[j].x) / ld(sum))));
			}
			now = vec[i];
			s += zs;
			zv.clear();
			zv.push_back(vec[i]);
		}
	}
	sort(ans.begin(), ans.end());
	for (int i = 0; i<int(ans.size()) - 1; i++)
	{
		if (ans[i].first == ans[i + 1].first)continue;
		if (ans[i].second.second > ans[i + 1].second.first - eps)continue;
		mini = min(mini, ld(ans[i + 1].first - ans[i].first) / (ans[i + 1].second.first - ans[i].second.second));
	}
	printf("%lf\n", double(mini));
}


#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
class Q
{
public:
	ll x, y;
	Q() {}
	Q(ll x, ll y) :x(x), y(y) {}
	bool operator < (Q q)const
	{
		return x*q.y < y*q.x;
	}
	bool operator == (Q q)const
	{
		return x*q.y == y*q.x;
	}
};
typedef long double ld;
typedef pair<ld, ld>pdd;
typedef pair<ll, ll>pii;
typedef pair<ll, ld>pid;
typedef pair<ll, pdd>pidd;
ld eps = 1e-14;
int main()
{
	int num;
	scanf("%d", &num);
	vector<Q>vec;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		vec.push_back(Q(z, 0));
	}
	ll sum = 0;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		vec[i].y = z;
		sum += z;
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	ld mini = 1.0;
	vector<pidd>ans;
	Q now = Q(0, 1);
	vector<Q>zv;
	ll s = 0;
	vec.push_back(Q(-1, 1));
	for (int i = 0; i <= num; i++)
	{
		if (now == vec[i])
		{
			zv.push_back(vec[i]);
		}
		else
		{
			ll zs = 0;
			for (int j = 0; j < zv.size(); j++)zs += zv[j].y;
			for (int j = 0; j < zv.size(); j++)
			{
				ans.push_back(make_pair(zv[j].x, make_pair(ld(s + zs)*ld(zv[j].x) / ld(sum), ld(s + zv[j].y)*ld(zv[j].x) / ld(sum))));
			}
			now = vec[i];
			s += zs;
			zv.clear();
			zv.push_back(vec[i]);
		}
	}
	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size() - 1; i++)if (ans[i].first == ans[i + 1].first)ans[i + 1].second.second = min(ans[i].second.second, ans[i + 1].second.second);
	for (int i = ans.size() - 1; i >= 1; i--)if (ans[i].first == ans[i - 1].first)ans[i - 1].second.first = max(ans[i - 1].second.first, ans[i].second.first);
	for (int i = 0; i < ans.size() - 1; i++)
	{
		if (ans[i].first == ans[i + 1].first)continue;
		if (ans[i].second.second > ans[i + 1].second.first - eps)continue;
		mini = min(mini, ld(ans[i + 1].first - ans[i].first) / (ans[i + 1].second.first - ans[i].second.second));
	}
	printf("%lf\n", double(mini));
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define SIZE 150005
#define BT 1024*256*2
#define EPS 1e-10

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
typedef pair <P,int> PP;

/*
�ő�̏�����l���āA
pi(1-c*x/T)+pj(1-c*(x+ti)/T) >=  pj(1-c*x/T)+pi(1-c*(x+tj)/T)
<=> pi*tj >= pj*ti
<=> pi/ti >= pj/tj
���Ap/t �̒l�� sort ���āA�����l�͂��낢�듮�����Ă���

--> paradox ������Ă������߂ɂ́Api<pj�̂��̂̓��_������ւ��Ƃ�������A
    t/p �̃T�C�Y���Ⴄ�Ƃ��́A�K����max,min���Ă����΂���
    �����łȂ�������A�ŏ��ƍŌ�ɂ��Ă��傿����Ƃ���
*/
struct segtree//max
{
	double seg[BT];
	int mum;

	void init(int n)
	{
		mum=1;
		while(mum<n) mum<<=1;
		for(int i=0;i<mum*2;i++) seg[i]=-1e10;
	}
	void add(int k,double x)
	{
		k+=mum-1;
		seg[k]=max(seg[k],x);
		while(k>0)
		{
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	double get(int a,int b,int k,int l,int r)
	{
		if(b<=l||r<=a) return -1e10;
		if(a<=l&&r<=b) return seg[k];
		else
		{
			double vl=get(a,b,k*2+1,l,(l+r)/2);
			double vr=get(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
	double get(int a,int b)
	{
		return get(a,b,0,0,mum);
	}
};
segtree mx,mn;
int tm[SIZE];
int pb[SIZE];
PP pos[SIZE];
vector <int> vec[SIZE];
vector <int> vx;
int n,sz;
ll all;

bool comp(const PP&l,const PP&r)//equal ���N�����炤�܂�sort�ł��Ȃ�
{
	P p=l.first,q=r.first;
	return (ll) p.first*(ll) q.second>(ll) p.second*(ll) q.first;
}
bool check(double x)
{
	mx.init(vx.size()+2);
	mn.init(vx.size()+2);
	ll sum=0;
	for(int i=0;i<sz;i++)
	{
		ll nxt=0;
		for(int j=0;j<vec[i].size();j++)
		{
			int v=vec[i][j];
			double f=vx[pb[v]]*(double) (1.0-x*(double) (sum+tm[v])/(double) all);
			//printf("%f : %d %f\n",x,v,f);
			if(pb[v]+1<vx.size())
			{
				double gt=-mn.get(pb[v]+1,vx.size());
				if(gt+EPS<f) return false;
			}
			mx.add(pb[v],f);
			nxt+=tm[v];
		}
		sum+=nxt;
		for(int j=0;j<vec[i].size();j++)
		{
			int v=vec[i][j];
			double f=vx[pb[v]]*(double) (1.0-x*(double) sum/(double) all);
			if(pb[v]>0)
			{
				double gt=mx.get(0,pb[v]);
				if(gt>f+EPS) return false;
			}
			mn.add(pb[v],-f);
		}
	}
	return true;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&pb[i]);
		vx.push_back(pb[i]);
	}
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	for(int i=0;i<n;i++) pb[i]=lower_bound(vx.begin(),vx.end(),pb[i])-vx.begin();
	for(int i=0;i<n;i++)
	{
		scanf("%d",&tm[i]);
		all+=tm[i];
		pos[i]=PP(P(vx[pb[i]],tm[i]),i);
	}
	sort(pos,pos+n,comp);
	sz=0;
	for(int i=0;i<n;)
	{
		PP p=pos[i];
		for(;i<n&&!comp(pos[i],p)&&!comp(p,pos[i]);i++) vec[sz].push_back(pos[i].second);
		sz++;
	}
	double l=0,r=1.0;
	//l=r=0.625;
	for(int i=0;i<30;i++)
	{
		double d=(l+r)/2;
		if(check(d)) l=d;
		else r=d;
	}
	printf("%.10f\n",l);
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define SIZE 150005
#define BT 1024*256*2
#define EPS 1e-10

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
typedef pair <P,int> PP;

/*
�ő�̏�����l���āA
pi(1-c*x/T)+pj(1-c*(x+ti)/T) >=  pj(1-c*x/T)+pi(1-c*(x+tj)/T)
<=> pi*tj >= pj*ti
<=> pi/ti >= pj/tj
���Ap/t �̒l�� sort ���āA�����l�͂��낢�듮�����Ă���

--> paradox ������Ă������߂ɂ́Api<pj�̂��̂̓��_������ւ��Ƃ�������A
    t/p �̃T�C�Y���Ⴄ�Ƃ��́A�K����max,min���Ă����΂���
    �����łȂ�������A�ŏ��ƍŌ�ɂ��Ă��傿����Ƃ���
*/
struct segtree//max
{
	double seg[BT];
	int mum;

	void init(int n)
	{
		mum=1;
		while(mum<n) mum<<=1;
		for(int i=0;i<mum*2;i++) seg[i]=-1e10;
	}
	void add(int k,double x)
	{
		k+=mum-1;
		seg[k]=max(seg[k],x);
		while(k>0)
		{
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	double get(int a,int b,int k,int l,int r)
	{
		if(b<=l||r<=a) return -1e10;
		if(a<=l&&r<=b) return seg[k];
		else
		{
			double vl=get(a,b,k*2+1,l,(l+r)/2);
			double vr=get(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
	double get(int a,int b)
	{
		return get(a,b,0,0,mum);
	}
};
segtree mx,mn;
int tm[SIZE];
int pb[SIZE];
PP pos[SIZE];
vector <int> vec[SIZE];
vector <int> vx;
int n,sz;
ll all;

bool comp(const PP&l,const PP&r)//equal ���N�����炤�܂�sort�ł��Ȃ�
{
	P p=l.first,q=r.first;
	return (ll) p.first*(ll) q.second>(ll) p.second*(ll) q.first;
}
bool check(double x)
{
	mx.init(vx.size()+2);
	mn.init(vx.size()+2);
	ll sum=0;
	for(int i=0;i<sz;i++)
	{
		ll nxt=0;
		for(int j=0;j<vec[i].size();j++)
		{
			int v=vec[i][j];
			double f=vx[pb[v]]*(double) (1.0-x*(double) (sum+tm[v])/(double) all);
			//printf("%f : %d %f\n",x,v,f);
			if(pb[v]+1<vx.size())
			{
				double gt=-mn.get(pb[v]+1,vx.size());
				if(gt+EPS<f) return false;
			}
			mx.add(pb[v],f);
			nxt+=tm[v];
		}
		sum+=nxt;
		for(int j=0;j<vec[i].size();j++)
		{
			int v=vec[i][j];
			double f=vx[pb[v]]*(double) (1.0-x*(double) sum/(double) all);
			if(pb[v]>0)
			{
				double gt=mx.get(0,pb[v]);
				if(gt>f+EPS) return false;
			}
			mn.add(pb[v],-f);
		}
	}
	return true;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&pb[i]);
		vx.push_back(pb[i]);
	}
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	for(int i=0;i<n;i++) pb[i]=lower_bound(vx.begin(),vx.end(),pb[i])-vx.begin();
	for(int i=0;i<n;i++)
	{
		scanf("%d",&tm[i]);
		all+=tm[i];
		pos[i]=PP(P(vx[pb[i]],tm[i]),i);
	}
	sort(pos,pos+n,comp);
	sz=0;
	for(int i=0;i<n;)
	{
		PP p=pos[i];
		for(;i<n&&!comp(pos[i],p)&&!comp(p,pos[i]);i++) vec[sz].push_back(pos[i].second);
		sz++;
	}
	double l=0,r=1.0;
	//l=r=0.625;
	for(int i=0;i<60;i++)
	{
		double d=(l+r)/2;
		if(check(d)) l=d;
		else r=d;
	}
	printf("%.10f\n",l);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define N (int)(1e5+10)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define inf mod
#define endl '\n'
#define sag (sol|1)
#define sol (root<<1)
#define ort ((bas+son)/2)
#define bit(x,y) ((x>>y)&1)

#define pi pair< pii , pair< double ,double > >
pi A[N];
int i,j,k,n,m,x,y,z,T;
double bas=0,son=1;

bool cmp(pi a,pi b){
	pii x = a.st;
	pii y = b.st;
	return x.st*(ort*x.nd/T)+y.st*(ort*(x.nd+y.nd)/T) <= y.st*(ort*y.nd/T)+x.st*(ort*(y.nd+x.nd)/T);
}

bool f(){
	sort(A+1,A+1+n,cmp);

	int s,t1=0,t2=0;

	for(int i=1 ; i<=n ; i++){
		int j=i;
		pii x = A[i].st;
		pii y = A[i+1].st;
		t2 += A[i].st.nd;
		while(i+1<=n and fabs((x.st*(ort*x.nd/T)+y.st*(ort*(x.nd+y.nd)/T)) - (y.st*(ort*y.nd/T)+x.st*(ort*(y.nd+x.nd)/T))) <= 0.000001){
			t2 += A[i+1].st.nd;
			i++;
			x = A[i].st;
			y = A[i+1].st;
		}

		for( ; j<=i ; j++){
			A[j].nd = mp(A[j].st.st*(1-ort*(t1+A[j].st.nd)/T) , A[j].st.st*(1-ort*(t2)/T));
		}

		t1 = t2;
	}

	sort(A+1,A+1+n);

	double mx=0,mx2=0;

	for(int i=1 ; i<=n ; ){
		int j = i;
		while(i<=n and A[i].st.st == A[j].st.st){
			mx2 = max(mx2,A[i].nd.st);
			if(mx > A[i].nd.nd)
				return 1;
			i++;
		}
		mx = mx2;
	}

	return 0;
}

int main(){
	cin >> n;

	for(i=1 ; i<=n ; i++)
		scanf("%d",&A[i].st.st);

	for(i=1 ; i<=n ; i++){
		scanf("%d",&A[i].st.nd);
		T += A[i].st.nd;
	}

	for(i=1 ; i<=30 ; i++){
		if(!f())
			bas=ort;
		else
			son=ort;
	}

	cout << setprecision(10) << fixed << bas << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define N (int)(2e5+10)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define inf mod
#define endl '\n'
#define sag (sol|1)
#define sol (root<<1)
#define ort ((bas+son)/2)
#define bit(x,y) ((x>>y)&1)

#define pi pair< pii , pair< double ,double > >
pi A[N];
int i,j,k,n,m,x,y,z,T;
double bas=0,son=1;

bool cmp(pi a,pi b){
	pii x = a.st;
	pii y = b.st;
	return x.st*(ort*x.nd/T)+y.st*(ort*(x.nd+y.nd)/T) <= y.st*(ort*y.nd/T)+x.st*(ort*(y.nd+x.nd)/T);
}

bool f(){
	sort(A+1,A+1+n,cmp);

	int s,t1=0,t2=0;

	for(int i=1 ; i<=n ; i++){
		int j=i;
		pii x = A[i].st;
		pii y = A[i+1].st;
		t2 += A[i].st.nd;
		while(i+1<=n and fabs((x.st*(ort*x.nd/T)+y.st*(ort*(x.nd+y.nd)/T)) - (y.st*(ort*y.nd/T)+x.st*(ort*(y.nd+x.nd)/T))) <= 0.000001){
			t2 += A[i+1].st.nd;
			i++;
			x = A[i].st;
			y = A[i+1].st;
		}

		for( ; j<=i ; j++){
			A[j].nd = mp(A[j].st.st*(1-ort*(t1+A[j].st.nd)/T) , A[j].st.st*(1-ort*(t2)/T));
		}

		t1 = t2;
	}

	sort(A+1,A+1+n);

	double mx=0,mx2=0;

	for(int i=1 ; i<=n ; ){
		int j = i;
		while(i<=n and A[i].st.st == A[j].st.st){
			mx2 = max(mx2,A[i].nd.st);
			if(mx > A[i].nd.nd)
				return 1;
			i++;
		}
		mx = mx2;
	}

	return 0;
}

int main(){
	cin >> n;

	for(i=1 ; i<=n ; i++)
		scanf("%d",&A[i].st.st);

	for(i=1 ; i<=n ; i++){
		scanf("%d",&A[i].st.nd);
		T += A[i].st.nd;
	}

	for(i=1 ; i<=30 ; i++){
		if(!f())
			bas=ort;
		else
			son=ort;
	}

	cout << setprecision(10) << fixed << bas << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define N (int)(2e5+10)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define inf mod
#define endl '\n'
#define sag (sol|1)
#define sol (root<<1)
#define ort ((bas+son)/2)
#define bit(x,y) ((x>>y)&1)

#define pi pair< pii , pair< double ,double > >
#define int long long
pi A[N];
int i,j,k,n,m,x,y,z,T;
double bas=0,son=1;

bool cmp(pi a,pi b){
	pii x = a.st;
	pii y = b.st;
	return x.st*(x.nd)+y.st*((x.nd+y.nd)) < y.st*(y.nd)+x.st*((y.nd+x.nd));
}

bool f(){
	sort(A+1,A+1+n,cmp);

	int s,t1=0,t2=0;

	for(int i=1 ; i<=n ; i++){
		int j=i;
		pii x = A[i].st;
		pii y = A[i+1].st;
		t2 += A[i].st.nd;
		while(i+1<=n and x.st*(x.nd)+y.st*((x.nd+y.nd)) == y.st*(y.nd)+x.st*((y.nd+x.nd))){
			t2 += A[i+1].st.nd;
			i++;
			x = A[i].st;
			y = A[i+1].st;
		}

		for( ; j<=i ; j++){
			A[j].nd = mp(A[j].st.st*(1-ort*(t1+A[j].st.nd)/T) , A[j].st.st*(1-ort*(t2)/T));
		}

		t1 = t2;
	}

	sort(A+1,A+1+n);

	double mx=0,mx2=0;

	for(int i=1 ; i<=n ; ){
		int j = i;
		while(i<=n and A[i].st.st == A[j].st.st){
			mx2 = max(mx2,A[i].nd.st);
			if(mx > A[i].nd.nd)
				return 1;
			i++;
		}
		mx = mx2;
	}

	return 0;
}

main(){
	cin >> n;

	for(i=1 ; i<=n ; i++)
		scanf("%lld",&A[i].st.st);

	for(i=1 ; i<=n ; i++){
		scanf("%lld",&A[i].st.nd);
		T += A[i].st.nd;
	}

	for(i=1 ; i<=30 ; i++){
		if(!f())
			bas=ort;
		else
			son=ort;
	}

	cout << setprecision(10) << fixed << bas << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define M 200200
typedef long long ll;
typedef pair<ll, ll> pll;

int n;
ll T;
pll pp[M];
bool cmp(pll a, pll b) {
    return a.first * b.second != a.second * b.first ? a.first * b.second > a.second * b.first : a.first > b.first;
}
ll p[M], t[M];
bool ok(int i, int j) {
    return p[i] * t[j] == p[j] * t[i];
}

int id[M];
bool cmp1(int i, int j) {
    return p[i] != p[j] ? p[i] < p[j] : i < j;
}

int pre[M], nxt[M];
double tt[M];
bool ok(double c) {
    double mx = 0;
    for (int j, i = 1; i <= n; i = j) {
        for (j = i; j <= n && p[id[j]] == p[id[i]]; j++) {
            int k = id[j];
            double pp = p[k] * (1 - c * tt[nxt[k]] / T);
            if (pp < mx) {
                return 0;
            }
        }

        for (j = i; j <= n && p[id[j]] == p[id[i]]; j++) {
            int k = id[j];
            double pp = p[k] * (1 - c * (tt[pre[k]-1] + t[k]) / T);
            mx = max(mx, pp);
        }
    }
    return 1;
}

int main() {
    //freopen("D2.in", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%I64d", &pp[i].first);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%I64d", &pp[i].second);
    }
    sort(pp + 1, pp + n + 1, cmp);
    for (int i = 1; i <= n; i++) {
        p[i] = pp[i].first;
        t[i] = pp[i].second;
        //printf("%I64d %I64d\n", p[i], t[i]);
        tt[i] = tt[i-1] + t[i];
        id[i] = i;
        T += t[i];
    }

    pre[1] = 1;
    for (int i = 2; i <= n; i++) {
        if (ok(i, i - 1)) {
            pre[i] = pre[i-1];
        } else {
            pre[i] = i;
        }
    }

    nxt[n] = n;
    for (int i = n - 1; i >= 1; i--) {
        if (ok(i, i + 1)) {
            nxt[i] = nxt[i+1];
        } else {
            nxt[i] = i;
        }
    }

    sort(id + 1, id + n + 1, cmp1);
    double mn = 0, mx = 1;
    for (int step = 0; step < 100; step++) {
        double mid = (mn + mx) / 2;
        if (ok(mid)) {
            mn = mid;
        } else {
            mx = mid;
        }
    }
    printf("%.11lf\n", mn);
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <utility>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>

#define inf 1000000007
#define pii pair<int,int>
#define pip pair<int,pii>
#define pll pair<long long,long long>
#define pif pair<int,double>
#define eps 1e-7

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) //fprintf(stderr,args)
#endif

#define pb push_back
#define maxn 200200

typedef long long ll;
using namespace std;

ll sum = 0;

#define double float

struct bla {
	int p,t,rel;
	bool operator<(bla comp)const{
		return (ll) p * comp.t > (ll) t * comp.p;
	}
	bool operator==(bla comp){
		return !(*this<comp) && !(comp<*this);
	}
	double eval(double c,ll x){
		return (double) p * (1.0 - c * (double) x / sum);
	}
};

bla v[maxn];

double T[2][4*maxn];

double query(int init,int fim,int p,int l,int r,int t){
	if(l > r || l > fim || r < init)
		return t ? -1 : 1e9;
	if(init >= l && fim <= r)
		return T[t][p];
	double a1,a2;
	int mid = (init+fim)/2;
	a1 = query(init,mid,2*p,l,r,t);
	a2 = query(mid+1,fim,2*p+1,l,r,t);
	if(t == 0)
		return min(a1,a2);
	else
		return max(a1,a2);
}

void update(int init,int fim,int p,int pos,double val,int t){
	if(init > pos || fim < pos)
		return;
	if(init == fim){
		if(t == 0)
			T[0][p] = min(T[0][p],val);
		else
			T[1][p] = max(T[1][p],val);
		return;
	}
	int mid = (init+fim)/2;
	update(init,mid,2*p,pos,val,t);
	update(mid+1,fim,2*p+1,pos,val,t);
	T[0][p] = min(T[0][2*p],T[0][2*p+1]);
	T[1][p] = max(T[1][2*p],T[1][2*p+1]);
}

void clear(int init,int fim,int p){
	T[0][p] = 1e9;
	T[1][p] = -1;
	if(init != fim){
		int mid = (init+fim)/2;
		clear(init,mid,2*p);
		clear(mid+1,fim,2*p+1);
	}
}

main(){

	int n;
	scanf("%d",&n);

	vector<int> cx;
	map<int,int> mp;

	for(int i=0;i<n;i++){
		scanf("%d",&v[i].p);
		cx.pb(v[i].p);
	}

	for(int i=0;i<n;i++){
		scanf("%d",&v[i].t);
		sum += v[i].t;
	}

	sort(cx.begin(), cx.end());

	mp[cx[0]] = 0;
	for(int i=1;i<n;i++){
		mp[cx[i]] = mp[cx[i-1]];
		if(cx[i-1] != cx[i])
			mp[cx[i]]++;
	}

	for(int i=0;i<n;i++)
		v[i].rel = mp[v[i].p];

	sort(v,v+n);

	double low = 0, up = 1;

	for(int k=0;k<25;k++){

		double mid = (low+up)/2;
		debug("mid %.8lf\n",mid);

		clear(0,n-1,1);

		int p = 0;
		ll tot = 0;

		int ok = 1;

		while(p < n){

			debug("p %d\n",p);
			int p0 = p;
			ll T = 0;
			while(p+1 < n && v[p] == v[p+1]){
				T += v[p].t;
				p++;
			}
			T += v[p].t;
			debug("T %d\n",(int)T);

			for(int i=p0;i<=p;i++){
				debug("i %d p %d t %d rel %d\n",i,v[i].p,v[i].t,v[i].rel);
				double men = v[i].eval(mid,tot+T);
				double mai = v[i].eval(mid,tot+v[i].t);
				debug("min %.8lf max %.8lf\n",men,mai);
				update(0,n-1,1,v[i].rel,men,0);
				update(0,n-1,1,v[i].rel,mai,1);
				if(query(0,n-1,1,0,v[i].rel-1,1) > men || query(0,n-1,1,v[i].rel+1,n-1,0) < mai)
					ok = 0;
			}

			tot += T;
			p++;

		}

		if(ok)
			low = mid;
		else
			up = mid;

	}

	printf("%.8lf\n",low);

}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <utility>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>

#define inf 1000000007
#define pii pair<int,int>
#define pip pair<int,pii>
#define pll pair<long long,long long>
#define pif pair<int,double>
#define eps 1e-7

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) //fprintf(stderr,args)
#endif

#define pb push_back
#define maxn 200200

typedef long long ll;
using namespace std;

ll sum = 0;

#define double float

struct bla {
	int p,t,rel;
	bool operator<(bla comp)const{
		return (ll) p * comp.t > (ll) t * comp.p;
	}
	inline bool operator==(bla comp){
		return !(*this<comp) && !(comp<*this);
	}
	inline double eval(double c,ll x){
		return (double) p * (1.0 - c * (double) x / sum);
	}
};

bla v[maxn];

double T[2][4*maxn];

inline double query(int init,int fim,int p,int l,int r,int t){
	if(l > r || l > fim || r < init)
		return t ? -1 : 1e9;
	if(init >= l && fim <= r)
		return T[t][p];
	double a1,a2;
	int mid = (init+fim)/2;
	a1 = query(init,mid,2*p,l,r,t);
	a2 = query(mid+1,fim,2*p+1,l,r,t);
	if(t == 0)
		return min(a1,a2);
	else
		return max(a1,a2);
}

inline void update(int init,int fim,int p,int pos,double val,int t){
	if(init > pos || fim < pos)
		return;
	if(init == fim){
		if(t == 0)
			T[0][p] = min(T[0][p],val);
		else
			T[1][p] = max(T[1][p],val);
		return;
	}
	int mid = (init+fim)/2;
	update(init,mid,2*p,pos,val,t);
	update(mid+1,fim,2*p+1,pos,val,t);
	T[0][p] = min(T[0][2*p],T[0][2*p+1]);
	T[1][p] = max(T[1][2*p],T[1][2*p+1]);
}

inline void clear(int init,int fim,int p){
	T[0][p] = 1e9;
	T[1][p] = -1;
	if(init != fim){
		int mid = (init+fim)/2;
		clear(init,mid,2*p);
		clear(mid+1,fim,2*p+1);
	}
}

int ret;
char ch;
inline int read(){
	ret = 0;
	while((ch=getchar()) >= '0')
		ret = 10*ret+ch-'0';
	return ret;
}

main(){

	int n = read();

	vector<int> cx;
	map<int,int> mp;

	for(int i=0;i<n;i++){
		v[i].p = read();
		cx.pb(v[i].p);
	}

	for(int i=0;i<n;i++){
		v[i].t = read();
		sum += v[i].t;
	}

	sort(cx.begin(), cx.end());

	mp[cx[0]] = 0;
	for(int i=1;i<n;i++){
		mp[cx[i]] = mp[cx[i-1]];
		if(cx[i-1] != cx[i])
			mp[cx[i]]++;
	}

	for(int i=0;i<n;i++)
		v[i].rel = mp[v[i].p];

	sort(v,v+n);

	double low = 0, up = 1;

	for(int k=0;k<25;k++){

		double mid = (low+up)/2;
		debug("mid %.8lf\n",mid);

		clear(0,n-1,1);

		int p = 0;
		ll tot = 0;

		int ok = 1;

		while(p < n){

			debug("p %d\n",p);
			int p0 = p;
			ll T = 0;
			while(p+1 < n && v[p] == v[p+1]){
				T += v[p].t;
				p++;
			}
			T += v[p].t;
			debug("T %d\n",(int)T);

			for(int i=p0;i<=p;i++){
				debug("i %d p %d t %d rel %d\n",i,v[i].p,v[i].t,v[i].rel);
				double men = v[i].eval(mid,tot+T);
				double mai = v[i].eval(mid,tot+v[i].t);
				debug("min %.8lf max %.8lf\n",men,mai);
				update(0,n-1,1,v[i].rel,men,0);
				update(0,n-1,1,v[i].rel,mai,1);
				if(query(0,n-1,1,0,v[i].rel-1,1) > men || query(0,n-1,1,v[i].rel+1,n-1,0) < mai)
					ok = 0;
			}

			tot += T;
			p++;

		}

		if(ok)
			low = mid;
		else
			up = mid;

	}

	printf("%.8lf\n",low);

}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <utility>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>

#define inf 1000000007
#define pii pair<int,int>
#define pip pair<int,pii>
#define pll pair<long long,long long>
#define pif pair<int,double>
#define eps 1e-7

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) //fprintf(stderr,args)
#endif

#define pb push_back
#define maxn 200200

typedef long long ll;
using namespace std;

ll sum = 0;

struct bla {
	int p,t,rel;
	bool operator<(bla comp)const{
		return (ll) p * comp.t > (ll) t * comp.p;
	}
	inline bool operator==(bla comp){
		return !(*this<comp) && !(comp<*this);
	}
	inline double eval(double c,ll x){
		return (double) p * (1.0 - c * (double) x / sum);
	}
};

bla v[maxn];

double T[2][4*maxn];

inline double query(int init,int fim,int p,int l,int r,int t){
	if(l > r || l > fim || r < init)
		return t ? -1 : 1e9;
	if(init >= l && fim <= r)
		return T[t][p];
	double a1,a2;
	int mid = (init+fim)/2;
	a1 = query(init,mid,2*p,l,r,t);
	a2 = query(mid+1,fim,2*p+1,l,r,t);
	if(t == 0)
		return min(a1,a2);
	else
		return max(a1,a2);
}

inline void update(int init,int fim,int p,int pos,double val,int t){
	if(init > pos || fim < pos)
		return;
	if(init == fim){
		if(t == 0)
			T[0][p] = min(T[0][p],val);
		else
			T[1][p] = max(T[1][p],val);
		return;
	}
	int mid = (init+fim)/2;
	update(init,mid,2*p,pos,val,t);
	update(mid+1,fim,2*p+1,pos,val,t);
	T[0][p] = min(T[0][2*p],T[0][2*p+1]);
	T[1][p] = max(T[1][2*p],T[1][2*p+1]);
}

inline void clear(int init,int fim,int p){
	T[0][p] = 1e9;
	T[1][p] = -1;
	if(init != fim){
		int mid = (init+fim)/2;
		clear(init,mid,2*p);
		clear(mid+1,fim,2*p+1);
	}
}

int ret;
char ch;
inline int read(){
	ret = 0;
	while((ch=getchar()) >= '0')
		ret = 10*ret+ch-'0';
	return ret;
}

main(){

	int n = read();

	vector<int> cx;
	map<int,int> mp;

	for(int i=0;i<n;i++){
		v[i].p = read();
		cx.pb(v[i].p);
	}

	for(int i=0;i<n;i++){
		v[i].t = read();
		sum += v[i].t;
	}

	sort(cx.begin(), cx.end());

	mp[cx[0]] = 0;
	for(int i=1;i<n;i++){
		mp[cx[i]] = mp[cx[i-1]];
		if(cx[i-1] != cx[i])
			mp[cx[i]]++;
	}

	for(int i=0;i<n;i++)
		v[i].rel = mp[v[i].p];

	sort(v,v+n);

	double low = 0, up = 1;

	for(int k=0;k<25;k++){

		double mid = (low+up)/2;
		debug("mid %.8lf\n",mid);

		clear(0,n-1,1);

		int p = 0;
		ll tot = 0;

		int ok = 1;

		while(p < n){

			debug("p %d\n",p);
			int p0 = p;
			ll T = 0;
			while(p+1 < n && v[p] == v[p+1]){
				T += v[p].t;
				p++;
			}
			T += v[p].t;
			debug("T %d\n",(int)T);

			for(int i=p0;i<=p;i++){
				debug("i %d p %d t %d rel %d\n",i,v[i].p,v[i].t,v[i].rel);
				double men = v[i].eval(mid,tot+T);
				double mai = v[i].eval(mid,tot+v[i].t);
				debug("min %.8lf max %.8lf\n",men,mai);
				update(0,n-1,1,v[i].rel,men,0);
				update(0,n-1,1,v[i].rel,mai,1);
				if(query(0,n-1,1,0,v[i].rel-1,1) > men || query(0,n-1,1,v[i].rel+1,n-1,0) < mai)
					ok = 0;
			}

			tot += T;
			p++;

		}

		if(ok)
			low = mid;
		else
			up = mid;

	}

	printf("%.8lf\n",low);

}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <utility>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>

#define inf 1000000007
#define pii pair<int,int>
#define pip pair<int,pii>
#define pll pair<long long,long long>
#define pif pair<int,double>
#define eps 1e-7

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

#define pb push_back
#define maxn 200200

typedef long long ll;
using namespace std;

ll sum = 0;

struct bla {
	int p,t,rel;
	bool operator<(bla comp)const{
		return (ll) p * comp.t > (ll) t * comp.p;
	}
	bool operator==(bla comp){
		return !(*this<comp) && !(comp<*this);
	}
	double eval(double c,ll x){
		return (double) p * (1.0 - c * (double) x / sum);
	}
};

bla v[maxn];

double T[2][4*maxn];

double query(int init,int fim,int p,int l,int r,int t){
	if(l > r || l > fim || r < init)
		return t ? -1 : 1e9;
	if(init >= l && fim <= r)
		return T[t][p];
	double a1,a2;
	int mid = (init+fim)/2;
	a1 = query(init,mid,2*p,l,r,t);
	a2 = query(mid+1,fim,2*p+1,l,r,t);
	if(t == 0)
		return min(a1,a2);
	else
		return max(a1,a2);
}

void update(int init,int fim,int p,int pos,double val,int t){
	if(init > pos || fim < pos)
		return;
	if(init == fim){
		if(t == 0)
			T[0][p] = min(T[0][p],val);
		else
			T[1][p] = max(T[1][p],val);
		return;
	}
	int mid = (init+fim)/2;
	update(init,mid,2*p,pos,val,t);
	update(mid+1,fim,2*p+1,pos,val,t);
	T[0][p] = min(T[0][2*p],T[0][2*p+1]);
	T[1][p] = max(T[1][2*p],T[1][2*p+1]);
}

void clear(int init,int fim,int p){
	T[0][p] = 1e9;
	T[1][p] = -1;
	if(init != fim){
		int mid = (init+fim)/2;
		clear(init,mid,2*p);
		clear(mid+1,fim,2*p+1);
	}
}

main(){

	int n;
	scanf("%d",&n);

	vector<int> cx;
	map<int,int> mp;

	for(int i=0;i<n;i++){
		scanf("%d",&v[i].p);
		cx.pb(v[i].p);
	}

	for(int i=0;i<n;i++){
		scanf("%d",&v[i].t);
		sum += v[i].t;
	}

	sort(cx.begin(), cx.end());

	mp[cx[0]] = 0;
	for(int i=1;i<n;i++){
		mp[cx[i]] = mp[cx[i-1]];
		if(cx[i-1] != cx[i])
			mp[cx[i]]++;
	}

	for(int i=0;i<n;i++)
		v[i].rel = mp[v[i].p];

	sort(v,v+n);

	double low = 0, up = 1;

	for(int k=0;k<25;k++){

		double mid = (low+up)/2;
		debug("mid %.8lf\n",mid);

		clear(0,n-1,1);

		int p = 0;
		ll tot = 0;

		int ok = 1;

		while(p < n){

			debug("p %d\n",p);
			int p0 = p;
			ll T = 0;
			while(p+1 < n && v[p] == v[p+1]){
				T += v[p].t;
				p++;
			}
			T += v[p].t;
			debug("T %d\n",(int)T);

			for(int i=p0;i<=p;i++){
				debug("i %d p %d t %d rel %d\n",i,v[i].p,v[i].t,v[i].rel);
				double men = v[i].eval(mid,tot+T);
				double mai = v[i].eval(mid,tot+v[i].t);
				debug("min %.8lf max %.8lf\n",men,mai);
				update(0,n-1,1,v[i].rel,men,0);
				update(0,n-1,1,v[i].rel,mai,1);
				if(query(0,n-1,1,0,v[i].rel-1,1) > men || query(0,n-1,1,v[i].rel+1,n-1,0) < mai)
					ok = 0;
			}

			tot += T;
			p++;

		}

		if(ok)
			low = mid;
		else
			up = mid;

	}

	printf("%.8lf\n",low);

}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iostream>
#include <cassert>

using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

//#define DEBUG
#ifdef DEBUG
	#define DEB printf
#else
	#define DEB(...)
#endif

typedef double D;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int MAXN = 1000006;//10^6

pii P[MAXN];
int per[MAXN];

bool cmp(const int &a, const int &b){
	return 1LL*P[a].x*P[b].y>1LL*P[b].x*P[a].y;
}
bool rowne(int a,int b){
	return 1LL*P[a].x*P[b].y==1LL*P[b].x*P[a].y;
}
LL najwcz[MAXN];
LL najp[MAXN];
int n;
LL T;
int t[MAXN];
bool dasie(D c){
	D best=0;
	D lastbest=0.;
	fru(i,n){
		D worst=P[i].x*(1.0-c*(najp[i]+t[i])/T);
		if(worst<best) return 0;
		DEB("dla goscia %d %d: worst = %lf best = %lf\n",P[i].x,P[i].y,worst,best);
		lastbest=max(lastbest,P[i].x*(1.-c*(najwcz[i]+t[i])/T));
		if(P[i].x!=P[i+1].x) best=max(best,lastbest);
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	fru(i,n) scanf("%d",&P[i].x);
	fru(i,n) scanf("%d",&P[i].y);
	sort(P,P+n);
	fru(i,n) t[i]=P[i].y;
	fru(i,n) per[i]=i;
	sort(per,per+n,cmp);
	LL sum=0;
	int j=0;
	for(int i=0;i<n;){
		DEB("grupa:\n");
		while(j<n && rowne(per[i],per[j])) ++j;
		LL tu=0;
		for(int a=i;a<j;++a) tu+=t[per[a]];
		for(int a=i;a<j;++a){
			DEB("-- %d\n",per[a]);
			najwcz[per[a]]=sum;
			najp[per[a]]=sum+tu-t[per[a]];
		}
		sum+=tu;
		i=j;
	}
	fru(i,n) DEB("%d, %d: nawjecz = %lld, najp = %lld\n",P[i].x,P[i].y,najwcz[i],najp[i]);
	T=sum;
	D p=0,k=1.00;
	if(0)printf("%d\n",dasie(0.7));
	else fru(i,40){
		D m=(p+k)/2;
		if(dasie(m)) p=m;
		else k=m;
	}
	printf("%.7lf\n",p);
	return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iostream>
#include <cassert>

using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

//#define DEBUG
#ifdef DEBUG
	#define DEB printf
#else
	#define DEB(...)
#endif

typedef double D;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int MAXN = 1000006;//10^6

pii P[MAXN];
int per[MAXN];

bool cmp(const int &a, const int &b){
	return 1LL*P[a].x*P[b].y>1LL*P[b].x*P[a].y;
}
bool rowne(int a,int b){
	return 1LL*P[a].x*P[b].y==1LL*P[b].x*P[a].y;
}
LL najwcz[MAXN];
LL najp[MAXN];
int n;
LL T;
int t[MAXN];
bool dasie(D c){
	D best=0;
	fru(i,n){
		D worst=P[i].x*(1.0-c*(najp[i]+t[i])/T);
		if(worst<best) return 0;
		best=max(best,P[i].x*(1.-c*(najwcz[i]+t[i])/T));
		DEB("dla goscia %d %d: worst = %lf best = %lf\n",P[i].x,P[i].y,worst,best);
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	fru(i,n) scanf("%d",&P[i].x);
	fru(i,n) scanf("%d",&P[i].y);
	sort(P,P+n);
	fru(i,n) t[i]=P[i].y;
	fru(i,n) per[i]=i;
	sort(per,per+n,cmp);
	LL sum=0;
	int j=0;
	for(int i=0;i<n;){
		DEB("grupa:\n");
		while(j<n && rowne(per[i],per[j])) ++j;
		LL tu=0;
		for(int a=i;a<j;++a) tu+=t[per[a]];
		for(int a=i;a<j;++a){
			DEB("-- %d\n",per[a]);
			najwcz[per[a]]=sum;
			najp[per[a]]=sum+tu-t[per[a]];
		}
		sum+=tu;
		i=j;
	}
	fru(i,n) DEB("%d, %d: nawjecz = %lld, najp = %lld\n",P[i].x,P[i].y,najwcz[i],najp[i]);
	T=sum;
	D p=0,k=1.00;
	if(0)dasie(0.7);
	else fru(i,30){
		D m=(p+k)/2;
		if(dasie(m)) p=m;
		else k=m;
	}
	printf("%.7lf\n",p);
	return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iostream>
#include <cassert>

using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

//#define DEBUG
#ifdef DEBUG
	#define DEB printf
#else
	#define DEB(...)
#endif

typedef double D;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int MAXN = 1000006;//10^6

pii P[MAXN];
int per[MAXN];

bool cmp(const int &a, const int &b){
	return 1LL*P[a].x*P[b].y>1LL*P[b].x*P[a].y;
}
bool rowne(int a,int b){
	return 1LL*P[a].x*P[b].y==1LL*P[b].x*P[a].y;
}
LL najwcz[MAXN];
LL najp[MAXN];
int n;
LL T;
int t[MAXN];
bool dasie(D c){
	D best=0;
	D lastbest=0;
	fru(i,n){
		D worst=P[i].x*(1.0-c*(najp[i]+t[i])/T);
		if(worst<best) return 0;
		if(i==n-1 || P[i].x!=P[i+1].x)best=max(best,P[i].x*(1.-c*(najwcz[i]+t[i])/T));
		DEB("dla goscia %d %d: worst = %lf best = %lf\n",P[i].x,P[i].y,worst,best);
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	fru(i,n) scanf("%d",&P[i].x);
	fru(i,n) scanf("%d",&P[i].y);
	sort(P,P+n);
	fru(i,n) t[i]=P[i].y;
	fru(i,n) per[i]=i;
	sort(per,per+n,cmp);
	LL sum=0;
	int j=0;
	for(int i=0;i<n;){
		DEB("grupa:\n");
		while(j<n && rowne(per[i],per[j])) ++j;
		LL tu=0;
		for(int a=i;a<j;++a) tu+=t[per[a]];
		for(int a=i;a<j;++a){
			DEB("-- %d\n",per[a]);
			najwcz[per[a]]=sum;
			najp[per[a]]=sum+tu-t[per[a]];
		}
		sum+=tu;
		i=j;
	}
	fru(i,n) DEB("%d, %d: nawjecz = %lld, najp = %lld\n",P[i].x,P[i].y,najwcz[i],najp[i]);
	T=sum;
	D p=0,k=1.00;
	if(0)dasie(0.7);
	else fru(i,40){
		D m=(p+k)/2;
		if(dasie(m)) p=m;
		else k=m;
	}
	printf("%.7lf\n",p);
	return 0;
}


#include <bits/stdc++.h>

#define INF 1e15
#define LL long long
#define fix fixed<<setprecision(10)
#define eps 1e-9

using namespace std;

const int N=201110;

int l[N],r[N],B[N],seg[N];
LL Lmin[N],Lmax[N],sT;
struct prob{
    int p,T;
}A[N];
map <int,int> mp;
double Min[N];
int n,k;
double inf,sup,mid,ans;

void build(int x,int L,int R){
    Min[x]=INF;
    l[x]=L;r[x]=R;
    if(L!=R){
        int mid=(L+R)/2;
        build(2*x,L,mid);
        build(2*x+1,mid+1,R);
    }
}

double getMin(int x,int L,int R){
    if(L>r[x]||R<l[x]) return INF;
    if(L<=l[x]&&R>=r[x]) return Min[x];
    return min(getMin(2*x,L,R),getMin(2*x+1,L,R));
}

void update(int x,int pos,double val){
    if(l[x]>pos||r[x]<pos) return;
    if(l[x]==pos&&r[x]==pos){
        Min[x]=min(Min[x],val);
        return;
    }
    update(2*x,pos,val);update(2*x+1,pos,val);
    Min[x]=min(Min[2*x],Min[2*x+1]);
}

bool Check(double c){
    build(1,1,n);
    for(int i=n;i>=1;i--){
        int u=B[i];
        //cout<<fix<<i<<" "<<u<<" "<<Lmax[seg[i]]<<" "<<A[i].p<<" "<<A[i].T<<" "<<(A[i].p*(1-c*(Lmax[seg[i]-1]+A[i].T)/sT))<<" "<<(A[i].p*(1-c*Lmax[seg[i]]/sT))<<endl;
        if(A[i].p*(1-c*(Lmax[seg[i]-1]+A[i].T)/sT)>getMin(1,u+1,n))
            return false;
        update(1,u,A[i].p*(1-c*Lmax[seg[i]]/sT));
    }
    return true;
}

bool comp(prob u,prob v){
    if(u.p*1.0/u.T==v.p*1.0/v.T)
        return u.p<v.p;
    return u.p*1.0/u.T>v.p*1.0/v.T;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("657D.inp","r",stdin);
        freopen("657D.out","w",stdout);
    #endif // ONLINE_JUDGE
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&A[i].p),B[i]=A[i].p;
    for(int i=1;i<=n;i++) scanf("%d",&A[i].T);
    sort(A+1,A+n+1,comp);
    sort(B+1,B+n+1);
    k=unique(B+1,B+n+1)-B;
    for(int i=1;i<k;i++) mp[B[i]]=i;
    for(int i=1;i<=n;i++) B[i]=mp[A[i].p];
    k=0;
    for(int i=1;i<=n;i++){
        sT+=A[i].T;
        if(i==1||A[i].p*1.0/A[i].T!=A[i-1].p*1.0/A[i-1].T){
            k++;
            Lmax[k-1]=sT-A[i].T;
        }
        seg[i]=k;
    }
    Lmax[k]=sT;
    inf=0;sup=1;
    for(int i=1;i<=50;i++){
        mid=(inf+sup)/2;
        if(Check(mid))
            ans=inf=mid;
        else
            sup=mid;
    }
    cout<<fix<<ans<<endl;
}


#include <bits/stdc++.h>

#define INF 1e15
#define LL long long
#define fix fixed<<setprecision(10)
#define eps 1e-9

using namespace std;

const int N=201110;

int l[4*N],r[4*N],B[N],seg[N];
LL Lmin[N],Lmax[N],sT;
struct prob{
    int p,T;
}A[N];
map <int,int> mp;
double Min[4*N];
int n,k;
double inf,sup,mid,ans;

void build(int x,int L,int R){
    Min[x]=INF;
    l[x]=L;r[x]=R;
    if(L!=R){
        int mid=(L+R)/2;
        build(2*x,L,mid);
        build(2*x+1,mid+1,R);
    }
}

double getMin(int x,int L,int R){
    if(L>r[x]||R<l[x]) return INF;
    if(L<=l[x]&&R>=r[x]) return Min[x];
    return min(getMin(2*x,L,R),getMin(2*x+1,L,R));
}

void update(int x,int pos,double val){
    if(l[x]>pos||r[x]<pos) return;
    if(l[x]==pos&&r[x]==pos){
        Min[x]=min(Min[x],val);
        return;
    }
    update(2*x,pos,val);update(2*x+1,pos,val);
    Min[x]=min(Min[2*x],Min[2*x+1]);
}

bool Check(double c){
    build(1,1,n);
    for(int i=n;i>=1;i--){
        int u=B[i];
        //cout<<fix<<i<<" "<<u<<" "<<Lmax[seg[i]]<<" "<<A[i].p<<" "<<A[i].T<<" "<<(A[i].p*(1-c*(Lmax[seg[i]-1]+A[i].T)/sT))<<" "<<(A[i].p*(1-c*Lmax[seg[i]]/sT))<<endl;
        if(A[i].p*(1-c*(Lmax[seg[i]-1]+A[i].T)/sT)>getMin(1,u+1,n))
            return false;
        update(1,u,A[i].p*(1-c*Lmax[seg[i]]/sT));
    }
    return true;
}

bool comp(prob u,prob v){
    if(u.p*1.0/u.T==v.p*1.0/v.T)
        return u.p<v.p;
    return u.p*1.0/u.T>v.p*1.0/v.T;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("657D.inp","r",stdin);
        freopen("657D.out","w",stdout);
    #endif // ONLINE_JUDGE
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&A[i].p),B[i]=A[i].p;
    for(int i=1;i<=n;i++) scanf("%d",&A[i].T);
    sort(A+1,A+n+1,comp);
    sort(B+1,B+n+1);
    k=unique(B+1,B+n+1)-B;
    for(int i=1;i<k;i++) mp[B[i]]=i;
    for(int i=1;i<=n;i++) B[i]=mp[A[i].p];
    k=0;
    for(int i=1;i<=n;i++){
        sT+=A[i].T;
        if(i==1||A[i].p*1.0/A[i].T!=A[i-1].p*1.0/A[i-1].T){
            k++;
            Lmax[k-1]=sT-A[i].T;
        }
        seg[i]=k;
    }
    Lmax[k]=sT;
    inf=0;sup=1;
    for(int i=1;i<=50;i++){
        mid=(inf+sup)/2;
        if(Check(mid))
            ans=inf=mid;
        else
            sup=mid;
    }
    cout<<fix<<ans<<endl;
}


#include <bits/stdc++.h>

#define LL long long
#define INF (LL)(1e18)

using namespace std;

const int N=201110;
int A[N];
priority_queue <LL> H[5];
LL Sum[5];
int n,Q,b,c;

void sub_1(){
    LL sum=0,ans=INF;
    for(int i=1;i<=Q;i++)
        sum+=A[i];
    for(int i=Q;i<=n;i++){
        sum-=A[i-Q];
        ans=min(ans,(LL)A[i]*Q-sum);
    }
    cout<<ans*c<<endl;
}

int MOD(int u){
    return u%5;
}

LL DIV (int u){
    return u/5;
}

void sub_2(){
    LL ans=INF,cur;
    int v;
    for(int i=0;i<5;i++) Sum[i]=INF,H[i].push(INF);
    for(int i=1;i<=n;i++){
        A[i]+=(int)(1e9);
        v=MOD(A[i]);
        for(int k=0;k<5;k++){
            if(k>=v)
                cur=-DIV(A[i])*b+(k-v)*c;
            else
                cur=-(DIV(A[i])+1)*b+(k+5-v)*c;
            Sum[k]+=cur;
            H[k].push(cur);
        }
        if(i<Q) continue;
        for(int k=0;k<5;k++){
            Sum[k]-=H[k].top();
            H[k].pop();
        }
        for(int k=0;k<5;k++){
            ans=min(ans,DIV(A[i]+k)*b*Q+Sum[MOD(A[i]+k)]);
        }
    }
    cout<<ans<<endl;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("657C.inp","r",stdin);
        freopen("657C.out","w",stdout);
    #endif // ONLINE_JUDGE
    scanf("%d%d%d%d",&n,&Q,&b,&c);
    for(int i=1;i<=n;i++)
        scanf("%d",&A[i]);
    sort(A+1,A+n+1);
    if(b>=5*c)
        sub_1();
    else
        sub_2();
}


#include <bits/stdc++.h>

#define INF 1e15
#define LL long long
#define fix fixed<<setprecision(10)
#define eps 1e-9

using namespace std;

const int N=201110;

int l[N],r[N],B[N],seg[N];
LL Lmin[N],Lmax[N],sT;
struct prob{
    int p,T;
}A[N];
map <int,int> mp;
double Min[N];
int n,k;
double inf,sup,mid,ans;

void build(int x,int L,int R){
    Min[x]=INF;
    l[x]=L;r[x]=R;
    if(L!=R){
        int mid=(L+R)/2;
        build(2*x,L,mid);
        build(2*x+1,mid+1,R);
    }
}

double getMin(int x,int L,int R){
    if(L>r[x]||R<l[x]) return INF;
    if(L<=l[x]&&R>=r[x]) return Min[x];
    return min(getMin(2*x,L,R),getMin(2*x+1,L,R));
}

void update(int x,int pos,double val){
    if(l[x]>pos||r[x]<pos) return;
    if(l[x]==pos&&r[x]==pos){
        Min[x]=min(Min[x],val);
        return;
    }
    update(2*x,pos,val);update(2*x+1,pos,val);
    Min[x]=min(Min[2*x],Min[2*x+1]);
}

bool Check(double c){
    build(1,1,n);
    for(int i=n;i>=1;i--){
        int u=B[i];
        if(A[i].p*(1-c*(Lmax[seg[i]-1]+A[i].T)/sT)>getMin(1,u+1,n))
            return false;
        update(1,u,A[i].p*(1-c*Lmax[seg[i]]/sT));
    }
    return true;
}

bool comp(prob u,prob v){
    if(u.p/u.T==v.p/v.T)
        return u.p<v.p;
    return u.p/u.T>v.p/v.T;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("657D.inp","r",stdin);
        freopen("657D.out","w",stdout);
    #endif // ONLINE_JUDGE
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&A[i].p),B[i]=A[i].p;
    for(int i=1;i<=n;i++) scanf("%d",&A[i].T);
    sort(A+1,A+n+1,comp);
    sort(B+1,B+n+1);
    k=unique(B+1,B+n+1)-B;
    for(int i=1;i<=k;i++) mp[B[i]]=i;
    for(int i=1;i<=n;i++) B[i]=mp[A[i].p];
    k=0;
    for(int i=1;i<=n;i++){
        sT+=A[i].T;
        if(i==1||A[i].p/A[i].T!=A[i-1].p/A[i-1].T){
            k++;
            Lmax[k-1]=sT-A[i].T;
        }
        seg[i]=k;
    }
    Lmax[k]=sT;
    inf=0;sup=1;
    for(int i=1;i<=50;i++){
        mid=(inf+sup)/2;
        if(Check(mid))
            ans=inf=mid;
        else
            sup=mid;
    }
    cout<<fix<<ans<<endl;
}


#include <bits/stdc++.h>

#define INF 1e15
#define LL long long
#define fix fixed<<setprecision(10)
#define eps 1e-9

using namespace std;

const int N=201110;

int l[N],r[N],B[N],seg[N];
LL Lmin[N],Lmax[N],sT;
struct prob{
    int p,T;
}A[N];
map <int,int> mp;
double Min[N];
int n,k;
double inf,sup,mid,ans;

void build(int x,int L,int R){
    Min[x]=INF;
    l[x]=L;r[x]=R;
    if(L!=R){
        int mid=(L+R)/2;
        build(2*x,L,mid);
        build(2*x+1,mid+1,R);
    }
}

double getMin(int x,int L,int R){
    if(L>r[x]||R<l[x]) return INF;
    if(L<=l[x]&&R>=r[x]) return Min[x];
    return min(getMin(2*x,L,R),getMin(2*x+1,L,R));
}

void update(int x,int pos,double val){
    if(l[x]>pos||r[x]<pos) return;
    if(l[x]==pos&&r[x]==pos){
        Min[x]=min(Min[x],val);
        return;
    }
    update(2*x,pos,val);update(2*x+1,pos,val);
    Min[x]=min(Min[2*x],Min[2*x+1]);
}

bool Check(double c){
    build(1,1,n);
    for(int i=n;i>=1;i--){
        int u=B[i];
        if(A[i].p*(1-c*(Lmax[seg[i]-1]+A[i].T)/sT)>getMin(1,u,n))
            return false;
        update(1,u,A[i].p*(1-c*Lmax[seg[i]]/sT));
    }
    return true;
}

bool comp(prob u,prob v){
    if(u.p/u.T==v.p/v.T)
        return u.p<v.p;
    return u.p/u.T>v.p/v.T;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("657D.inp","r",stdin);
        freopen("657D.out","w",stdout);
    #endif // ONLINE_JUDGE
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&A[i].p),B[i]=A[i].p;
    for(int i=1;i<=n;i++) scanf("%d",&A[i].T);
    sort(A+1,A+n+1,comp);
    sort(B+1,B+n+1);
    k=unique(B+1,B+n+1)-B;
    for(int i=1;i<=k;i++) mp[B[i]]=i;
    for(int i=1;i<=n;i++) B[i]=mp[A[i].p];
    k=0;
    for(int i=1;i<=n;i++){
        sT+=A[i].T;
        if(i==1||A[i].p/A[i].T!=A[i-1].p/A[i-1].T){
            k++;
            Lmax[k-1]=sT-A[i].T;
        }
        seg[i]=k;
    }
    Lmax[k]=sT;
    inf=0;sup=1;
    for(int i=1;i<=50;i++){
        mid=(inf+sup)/2;
        if(Check(mid))
            ans=inf=mid;
        else
            sup=mid;
    }
    cout<<fix<<ans<<endl;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef long double ld;

const int Maxn = 200005;

int n;
ii pt[Maxn];
ld T;
ld mnpoints[Maxn], mxpoints[Maxn];
int ind[Maxn];

bool Eq(const ii &a, const ii &b)
{
	return ll(a.first) * ll(b.second) == ll(b.first) * ll(a.second);
}

bool Less(const ii &a, const ii &b)
{
	if (ll(a.first) * ll(b.second) != ll(b.first) * ll(a.second))
		return ll(a.first) * ll(b.second) > ll(b.first) * ll(a.second);
	return a.first < b.first;
}

bool Less2(const int &a, const int &b)
{
	return pt[a].first > pt[b].first;
}

bool Paradox(ld c)
{
	ld tim = 0.0;
	for (int i = 0, j; i < n; i = j) {
		ld sum = 0.0l;
		j = i;
		while (j < n && Eq(pt[i], pt[j])) {
			sum += pt[j].second;
			j++;
		}
		j = i;
		while (j < n && Eq(pt[i], pt[j])) {
			mnpoints[j] = ld(pt[j].first) * (1.0l - c * (tim + sum) / T);
			mxpoints[j] = ld(pt[j].first) * (1.0l - c * (tim + ld(pt[j].second)) / T);
			j++;
		}
		tim += sum;
	}
	ld mn = 1e9l;
	for (int i = 0, j; i < n; i = j) {
		j = i;
		ld mymn = 1e9l;
		while (j < n && pt[ind[i]].first == pt[ind[j]].first) {
			if (mn < mxpoints[ind[j]]) return true;
			mymn = min(mymn, mnpoints[ind[j]]);
			j++;
		}
		mn = min(mn, mymn);
	}
	return false;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &pt[i].first);
	for (int i = 0; i < n; i++) {
		scanf("%d", &pt[i].second);
		T += pt[i].second;
	}
	sort(pt, pt + n, Less);
	for (int i = 0; i < n; i++)
		ind[i] = i;
	sort(ind, ind + n, Less2);
	ld lef = 0, rig = 1;
	for (int i = 0; i < 40; i++) {
		ld mid = (lef + rig) / 2.0l;
		if (Paradox(mid)) rig = mid;
		else lef = mid;
	}
	cout << fixed << setprecision(10) << lef << endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

int N;
long long T;
long long p[150000],t[150000];
int cid[150000];
int pid[150000];
double low[150000],high[150000];

bool cmp(int a,int b)
{
	return p[a]*t[b] > p[b]*t[a];
}

bool pcmp(int a,int b)
{
	return p[a]<p[b];
}

bool pos(double c)
{
	int start = 0;
	long long sumt = 0;
	for(int i=0;i<N;i++)
	{
		if(i<N-1 && (!cmp(cid[i],cid[i+1])) && (!cmp(cid[i+1],cid[i])))
			continue;
		long long lowt = sumt;
		for(int j=start;j<=i;j++)
			sumt += t[cid[j]];
		for(int j=start;j<=i;j++)
		{
			low[cid[j]] = p[cid[j]]*(1 - c*(((double)(sumt))/T));
			high[cid[j]] = p[cid[j]]*(1 - c*(((double)(lowt+t[cid[j]]))/T));
			//cout << cid[j] << ": " << lowt << ": " << low[cid[j]] << ' ' << high[cid[j]] << '\n';
		}
		start = i+1;
	}
	double mx = 0.0;
	for(int i=0;i<N;i++)
	{
		if(low[pid[i]] < mx)
			return 0;
		mx = max(mx,high[pid[i]]);
	}
	return 1;
}

double binSearch(double low,double high,int iter)
{
	if(iter==60) return low;
	double mid = (low+high)/2;
	if(pos(mid)) return binSearch(mid,high,iter+1);
	else return binSearch(low,mid,iter+1);
}

int main()
{
	cin >> N;
	for(int i=0;i<N;i++)
		cin >> p[i];
	for(int i=0;i<N;i++)
	{
		cin >> t[i];
		T += t[i];
	}
	for(int i=0;i<N;i++)
		cid[i] = pid[i] = i;
	sort(cid,cid+N,cmp);
	sort(pid,pid+N,pcmp);
	cout << fixed << setprecision(20) << binSearch(0,1,0) << '\n';
}


#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

int N;
long long T;
long long p[150000],t[150000];
int cid[150000];
int pid[150000];
double low[150000],high[150000];

bool cmp(int a,int b)
{
	return p[a]*t[b] > p[b]*t[a];
}

bool pcmp(int a,int b)
{
	return p[a]<p[b];
}

bool pos(double c)
{
	int start = 0;
	long long sumt = 0;
	for(int i=0;i<N;i++)
	{
		if(i<N-1 && (!cmp(cid[i],cid[i+1])) && (!cmp(cid[i+1],cid[i])))
			continue;
		long long lowt = sumt;
		for(int j=start;j<=i;j++)
			sumt += t[cid[j]];
		for(int j=start;j<=i;j++)
		{
			low[cid[j]] = p[cid[j]]*(1 - c*(((double)(sumt))/T));
			high[cid[j]] = p[cid[j]]*(1 - c*(((double)(lowt+t[cid[j]]))/T));
			//cout << cid[j] << ": " << lowt << ": " << low[cid[j]] << ' ' << high[cid[j]] << '\n';
		}
		start = i+1;
	}
	double mx = 0.0;
	int j = 0;
	for(int i=0;i<N;i++)
	{
		while(j<N && p[pid[j]] < p[pid[i]])
			mx = max(mx,high[pid[j++]]);
		if(mx > low[pid[i]])
			return 0;
	}
	return 1;
}

double binSearch(double low,double high,int iter)
{
	if(iter==60) return low;
	double mid = (low+high)/2;
	if(pos(mid)) return binSearch(mid,high,iter+1);
	else return binSearch(low,mid,iter+1);
}

int main()
{
	cin >> N;
	for(int i=0;i<N;i++)
		cin >> p[i];
	for(int i=0;i<N;i++)
	{
		cin >> t[i];
		T += t[i];
	}
	for(int i=0;i<N;i++)
		cid[i] = pid[i] = i;
	sort(cid,cid+N,cmp);
	sort(pid,pid+N,pcmp);
	cout << fixed << setprecision(20) << binSearch(0,1,0) << '\n';
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct point{
	int p,t;
}A[160000];
double L[160000],R[160000];
long long tot=0;
int a[160000];
int n;
int compare(point k1,point k2){
	return 1ll*k1.t*k2.p<1ll*k2.t*k1.p;
}
int compare2(int k1,int k2){
	return A[k1].p<A[k2].p||(A[k1].p==A[k2].p&&k1>k2);
}
int check(double k1){
	long long rem=0; int pre=1;
	for (int i=2;i<=n+1;i++){
		//cout<<"fa "<<i<<" "<<compare(A[i],A[i-1])<<" "<<compare(A[i-1],A[i])<<endl;
		if (i>n||compare(A[i],A[i-1])||compare(A[i-1],A[i])){
			for (int j=pre;j<i;j++) R[j]=(double)A[j].p*(1-k1*(rem+A[j].t)/tot);
			for (int j=pre;j<i;j++) rem+=A[j].t;
			for (int j=pre;j<i;j++) L[j]=(double)A[j].p*(1-k1*rem/tot);
			pre=i;
		}
	}
	//for (int i=1;i<=n;i++) cout<<A[i].p<<" "<<A[i].t<<" "<<L[i]<<" "<<R[i]<<endl;
	double ma=0;
	pre=1;
	for (int i=2;i<=n;i++){
		if (A[a[i]].p!=A[a[i-1]].p){
			for (int j=pre;j<i;j++) ma=max(ma,R[a[j]]); pre=i;
		}
		if (L[a[i]]<ma) return 0;
	}
	return 1;
		/*
	for (int i=1;i<=n;i++){
		rem+=A[i].t; w[i]=(double)A[i].p*(1-k1*rem/tot);
	}
	int pre=0;
	for (int i=1;i<n;i++){
		double k1=w[a[i]],k2=w[a[i+1]];
		if (k1>k2) return 0;
	}
	return 1;*/
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i].p);
	for (int i=1;i<=n;i++) scanf("%d",&A[i].t);
	for (int i=1;i<=n;i++) tot+=A[i].t;
	sort(A+1,A+n+1,compare);
	for (int i=1;i<=n;i++) a[i]=i;
	sort(a+1,a+n+1,compare2);
//	check(0.32); while (1);
	double l=0,r=1;
	for (int i=1;i<=50;i++){
		double mid=(l+r)/2;
		if (check(mid)) l=mid; else r=mid;
	}
	printf("%.11lf\n",(l+r)/2);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (root+root)
#define sag (root+root+1)
#define orta ((bas+son)/2)
#define ll long long
#define pii pair<int,int>
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

const int N=1e5+5;
const int mod=1e9+7;
const int inf=1e9+7;

int n,i,j,k,w;
int P[N],ord[N],T[N];

pii A[N];

bool bek;

ll q,e,all;

double bas,son,ort,last;
double ans[N];

vector<pair<double,int> > Q;

bool cmp(int x,int y){
	if((ll)P[x]*T[y]==(ll)P[y]*T[x])
		return P[x]>P[y];
	return P[x]*T[y]>P[y]*T[x];
}

main(){

	scanf("%d",&n);

	for(i=1 ; i<=n ; i++){
		scanf("%d",P+i);
		A[i].st=P[i];
		A[i].nd=i;
	}
	for(i=1 ; i<=n ; i++){
		scanf("%d",T+i);
		all+=T[i];
		ord[i]=i;
	}

	sort(A+1,A+n+1);

	bas=0;
	son=1;

	sort(ord+1,ord+n+1,cmp);

	for(j=1 ; j<=50 ; j++){
		ort=(bas+son)/2.0;
		q=0;
		Q.clear();
		for(i=1 ; i<=n ; i++){
			k=i;
			e=T[ord[k]];
			while(k<n and (ll)(P[ord[i]]*T[ord[k+1]])==(ll)(P[ord[k+1]]*T[ord[i]])){
				e+=T[ord[k+1]];
				k++;
			}
			w=i;
			while(w<=k){
				Q.pb(mp(P[ord[w]]*(1.0-ort*((double)(q+e)/all)),P[ord[w]]));
				Q.pb(mp(P[ord[w]]*(1.0-ort*((double)(q+T[ord[w]])/all)),P[ord[w]]));
				w++;
			}
			q+=e;
			i=k;
		}
		last=0;
		bek=1;
		sort(Q.begin(),Q.end());
		last=0;
		for(i=0 ; i<Q.size() ; i++){
			if(Q[i].nd<last)
				bek=0;
			last=Q[i].nd;
		}
		if(bek)
			bas=ort;
		else son=ort;
	}

	printf("%.8lf",bas);
}