import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BResale {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.InputStream; InputStream java.io public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BResale solver = new BResale();
        solver.solve(1, in, out);
        out.close();
    }

    static class BResale {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BResale solver = new BResale();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BResale solver = new BResale();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out inputClass in = new inputClass(inputStream); in new inputClass(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) BResale solver = new BResale(); solver new BResale() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class BResale {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        }

    } BResale public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        } solve {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] value = new int[n]; value new int[n] n for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                value[i] = sc.nextInt();
            } {
                value[i] = sc.nextInt();
            } value[i] = sc.nextInt() value[i] value i sc.nextInt() sc.nextInt sc int[] cost = new int[n]; cost new int[n] n for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                cost[i] = sc.nextInt();
            } {
                cost[i] = sc.nextInt();
            } cost[i] = sc.nextInt() cost[i] cost i sc.nextInt() sc.nextInt sc int[][] dp = new int[n + 1][51 * n]; dp new int[n + 1][51 * n] n + 1 n 1 51 * n 51 n boolean[][] go = new boolean[n + 1][51 * n]; go new boolean[n + 1][51 * n] n + 1 n 1 51 * n 51 n go[0][0] = true go[0][0] go[0] go 0 0 true for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            } {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            } for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                } int j = 0; int j = 0; j 0 j < 51 * n j 51 * n 51 n j++ j++ j {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                } {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                } if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    } go[i][j] go[i] go i j {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    } if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        } !go[i + 1][j] go[i + 1][j] go[i + 1] go i + 1 i 1 j {
                            dp[i + 1][j] = dp[i][j];
                        } dp[i + 1][j] = dp[i][j] dp[i + 1][j] dp[i + 1] dp i + 1 i 1 j dp[i][j] dp[i] dp i j {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        } if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            } j - dp[i + 1][j] < j - dp[i][j] j - dp[i + 1][j] j dp[i + 1][j] dp[i + 1] dp i + 1 i 1 j j - dp[i][j] j dp[i][j] dp[i] dp i j {
                                dp[i + 1][j] = dp[i][j];
                            } dp[i + 1][j] = dp[i][j] dp[i + 1][j] dp[i + 1] dp i + 1 i 1 j dp[i][j] dp[i] dp i j go[i + 1][j] = true go[i + 1][j] go[i + 1] go i + 1 i 1 j true if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        } !go[i + 1][j + value[i]] go[i + 1][j + value[i]] go[i + 1] go i + 1 i 1 j + value[i] j value[i] value i {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } dp[i + 1][j + value[i]] = dp[i][j] + cost[i] dp[i + 1][j + value[i]] dp[i + 1] dp i + 1 i 1 j + value[i] j value[i] value i dp[i][j] + cost[i] dp[i][j] dp[i] dp i j cost[i] cost i {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        } if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            } j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i] j + value[i] - dp[i + 1][j + value[i]] j + value[i] j value[i] value i dp[i + 1][j + value[i]] dp[i + 1] dp i + 1 i 1 j + value[i] j value[i] value i j + value[i] - dp[i][j] - cost[i] j + value[i] - dp[i][j] - cost[i] j + value[i] j value[i] value i dp[i][j] dp[i] dp i j cost[i] cost i {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            } dp[i + 1][j + value[i]] = dp[i][j] + cost[i] dp[i + 1][j + value[i]] dp[i + 1] dp i + 1 i 1 j + value[i] j value[i] value i dp[i][j] + cost[i] dp[i][j] dp[i] dp i j cost[i] cost i go[i + 1][j + value[i]] = true go[i + 1][j + value[i]] go[i + 1] go i + 1 i 1 j + value[i] j value[i] value i true int max = 0; max 0 for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            } int i = 0; int i = 0; i 0 i < 51 * n i 51 * n 51 n i++ i++ i {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            } {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            } if (go[n][i])
                    max = Math.max(max, i - dp[n][i]); go[n][i] go[n] go n i max = Math.max(max, i - dp[n][i]) max Math.max(max, i - dp[n][i]) Math.max Math max i - dp[n][i] i dp[n][i] dp[n] dp n i out.println(max) out.println out max int testNumber testNumber inputClass sc sc PrintWriter out out static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    } inputClass BufferedReader br; br StringTokenizer st; st public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        } inputClass {

            br = new BufferedReader(new InputStreamReader(in));
        } br = new BufferedReader(new InputStreamReader(in)) br new BufferedReader(new InputStreamReader(in)) InputStream in in public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } next {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    st = new StringTokenizer(br.readLine());
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BResale solver = new BResale();
        solver.solve(1, in, out);
        out.close();
    }

    static class BResale {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BResale solver = new BResale();
        solver.solve(1, in, out);
        out.close();
    }

    static class BResale {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BResale {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int[] value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = sc.nextInt();
            }
            int[] cost = new int[n];
            for (int i = 0; i < n; i++) {
                cost[i] = sc.nextInt();
            }

            int[][] dp = new int[n + 1][51 * n];
            boolean[][] go = new boolean[n + 1][51 * n];

            go[0][0] = true;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 51 * n; j++) {
                    if (go[i][j]) {
                        if (!go[i + 1][j]) {
                            dp[i + 1][j] = dp[i][j];
                        } else {
                            if (j - dp[i + 1][j] < j - dp[i][j]) {
                                dp[i + 1][j] = dp[i][j];
                            }
                        }
                        go[i + 1][j] = true;

                        if (!go[i + 1][j + value[i]]) {
                            dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                        } else {
                            if (j + value[i] - dp[i + 1][j + value[i]] < j + value[i] - dp[i][j] - cost[i]) {
                                dp[i + 1][j + value[i]] = dp[i][j] + cost[i];
                            }
                        }
                        go[i + 1][j + value[i]] = true;
                    }
                }
            }

            int max = 0;
            for (int i = 0; i < 51 * n; i++) {
                if (go[n][i])
                    max = Math.max(max, i - dp[n][i]);
            }
            out.println(max);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}

