Problem:
Score : 200 points

Problem Statement

There are N gems. The value of the i-th gem is V_i.

You will choose some of these gems, possibly all or none, and get them.

However, you need to pay a cost of C_i to get the i-th gem.

Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.

Find the maximum possible value of X-Y.

Constraints

All values in input are integers.

1 \leq N \leq 20

1 \leq C_i, V_i \leq 50

Input

Input is given from Standard Input in the following format:

N
V_1 V_2 ... V_N
C_1 C_2 ... C_N

Output

Print the maximum possible value of X-Y.

Sample Input 1

3
10 2 5
6 3 4

Sample Output 1

5

If we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.
We have X-Y = 5 here, which is the maximum possible value.

Sample Input 2

4
13 21 6 19
11 30 6 15

Sample Output 2

6

Sample Input 3

1
1
50

Sample Output 3

0

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

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());
        }

    }
}