import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] b = in.readIntArray(n);
            int[] k = in.readIntArray(n);

            TaskF.PairLong[] coef = new TaskF.PairLong[n];
            for (int i = 0; i < n; ++i)
                coef[i] = new TaskF.PairLong(b[i] * 1000L, k[i]);

//        Arrays.sort(coef, Comparator.reverseOrder());

            long low = 0L, high = (long) 1e12;
            while (low <= high) {
                long mid = low + high >> 1;
                if (isFeasible(mid, n, coef)) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }

            out.println(low);
        }

        private boolean isFeasible(long threshold, int n, TaskF.PairLong[] coef) {
            long INF = (long) 1e17;
            long[][] dp = new long[n + 1][n + 1];
            for (long[] dpi : dp)
                Arrays.fill(dpi, INF);

            TaskF.PairLong[] b = new TaskF.PairLong[n];
            for (int i = 0; i < n; ++i)
                b[i] = new TaskF.PairLong(coef[i].first, coef[i].first - threshold * coef[i].second);

            Arrays.sort(b, Comparator.reverseOrder());

            dp[0][0] = 0L;

            int L = 0;
            while (L < n) {
                int R = L;
                while (R < n && b[R].first == b[L].first)
                    ++R;

                for (int was = 0; was <= L; ++was) {
                    if (dp[L][was] == INF) continue;

                    long sum = dp[L][was];
                    for (int i = L; i < R; ++i)
                        sum += b[i].second;

                    for (int cnt = 0; cnt <= R - L && cnt <= was; ++cnt) {
                        dp[R][was - cnt + R - L - cnt] = MathUtils.min(dp[R][was - cnt + R - L - cnt], sum);
                        if (L + cnt < n)
                            sum -= b[L + cnt].second;
                    }
                }

                L = R;
            }

            for (int i = 0; i <= n; i++)
                if (dp[n][i] <= 0) return true;

            return false;
        }

        static class PairLong implements Comparable<TaskF.PairLong> {
            long first;
            long second;

            public PairLong(long first, long second) {
                this.first = first;
                this.second = second;
            }


            public int compareTo(TaskF.PairLong o) {
                if (this.first != o.first)
                    return Long.compare(this.first, o.first);
                return Long.compare(this.second, o.second);
            }


            public String toString() {
                return String.format("{" + first + ", " + second + '}');
            }

        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }

    }

    static class MathUtils {
        public static long min(long... args) {
            long res = args[0];
            for (int i = 1; i < args.length; ++i)
                if (res > args[i])
                    res = args[i];
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }

    }
}

