import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.util.SplittableRandom; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn */ public class Solution { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); CloudyDay solver = new CloudyDay(); solver.solve(1, in, out); out.close(); } static class CloudyDay { static CloudyDay.Town[] a; static CloudyDay.Cloud[] c; static long[] seg; public void solve(int testNumber, FastReader in, PrintWriter out) { Debug debug = new Debug(out); int n = in.nextInt(); a = new CloudyDay.Town[n + 1]; for (int i = 0; i < n; ++i) { a[i] = new CloudyDay.Town(); a[i].pop = in.nextInt(); } a[n] = new CloudyDay.Town(); a[n].x = Integer.MAX_VALUE; a[n].pop = 0; for (int i = 0; i < n; ++i) a[i].x = in.nextInt(); int m = in.nextInt(); c = new CloudyDay.Cloud[m]; int ptr = 0; long[] comp = new long[2 * m + n * 2 + 100]; for (int i = 0; i <= n; ++i) comp[ptr++] = a[i].x; for (int i = 0; i < m; ++i) { c[i] = new CloudyDay.Cloud(); c[i].x = in.nextInt(); } for (int i = 0; i < m; ++i) { c[i].range = in.nextInt(); c[i].lower = c[i].x - c[i].range; c[i].upper = c[i].x + c[i].range; comp[ptr++] = c[i].lower; comp[ptr++] = c[i].upper; } comp = Arrays.copyOf(comp, ptr); ArrayUtils.sort(comp); comp = ArrayUtils.uniqueArray(comp); ArrayUtils.sort(a); for (int i = 0; i < m; ++i) { c[i].lower = Arrays.binarySearch(comp, c[i].lower); c[i].upper = Arrays.binarySearch(comp, c[i].upper); } long[] ax = new long[n + 1]; for (int i = 0; i <= n; ++i) a[i].x = ax[i] = Arrays.binarySearch(comp, a[i].x); for (int i = 0; i < m; ++i) { int ind1 = ArrayUtils.LowerBound(ax, c[i].lower); int ind2 = ArrayUtils.UpperBound(ax, c[i].upper); a[ind1].usedBy += 1; a[ind2].usedBy -= 1; //debug.tr(ind1, ind2, "dljfbksd"); } long unused = 0; for (int i = 1; i <= n; ++i) a[i].usedBy += a[i - 1].usedBy; for (int i = 0; i <= n; ++i) if (a[i].usedBy == 0) unused += a[i].pop; seg = new long[a.length << 2]; build(0, a.length - 1, 0); long max = 0; for (int i = 0; i < m; ++i) { int ind1 = ArrayUtils.LowerBound(ax, c[i].lower); int ind2 = ArrayUtils.UpperBound(ax, c[i].upper) - 1; max = Math.max(max, query(0, a.length - 1, 0, ind1, ind2) + unused); } out.println(max); } public static void build(int s, int e, int c) { if (s == e) { seg[c] = (a[s].usedBy == 1) ? a[s].pop : 0; return; } int m = (s + e) >>> 1; build(s, m, 2 * c + 1); build(m + 1, e, 2 * c + 2); seg[c] = seg[2 * c + 1] + seg[2 * c + 2]; } public static long query(int s, int e, int c, int l, int r) { if (l > r || s > e || l > e || r < s) return 0; if (s == e) { return seg[c]; } if (s >= l && e <= r) { return seg[c]; } int m = (s + e) >>> 1; return query(s, m, 2 * c + 1, l, r) + query(m + 1, e, 2 * c + 2, l, r); } static class Town implements Comparable { int pop; long x; int usedBy; public int compareTo(CloudyDay.Town o) { return Long.compare(x, o.x); } public String toString() { return x + " " + usedBy; } } static class Cloud implements Comparable { long x; long range; long lower; long upper; public int compareTo(CloudyDay.Cloud o) { return Long.compare(x, o.x); } } } static class ArrayUtils { public static int LowerBound(long[] a, long v) { int high = a.length; int low = -1; while (high - low > 1) { int mid = (high + low) >>> 1; if (a[mid] >= v) { high = mid; } else { low = mid; } } return high; } public static int UpperBound(long[] a, long v) { int high = a.length; int low = -1; while (high - low > 1) { int mid = (high + low) >>> 1; if (a[mid] > v) { high = mid; } else { low = mid; } } return high; } public static long[] sort(long[] a) { a = shuffle(a, new SplittableRandom()); Arrays.sort(a); return a; } public static Object[] sort(Object[] a) { a = shuffle(a, new SplittableRandom()); Arrays.sort(a); return a; } public static Object[] shuffle(Object[] a, SplittableRandom gen) { for (int i = 0, n = a.length; i < n; i++) { int ind = gen.nextInt(n - i) + i; Object d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; } public static long[] shuffle(long[] a, SplittableRandom gen) { for (int i = 0, n = a.length; i < n; i++) { int ind = gen.nextInt(n - i) + i; long d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; } public static long[] uniqueArray(long[] a) { int n = a.length; int p = 0; for (int i = 0; i < n; i++) { if (i == 0 || a[i] != a[i - 1]) a[p++] = a[i]; } return Arrays.copyOf(a, p); } } static class FastReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar; private int pnumChars; public FastReader(InputStream stream) { this.stream = stream; } private int pread() { if (pnumChars == -1) { throw new InputMismatchException(); } if (curChar >= pnumChars) { curChar = 0; try { pnumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (pnumChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = pread(); while (isSpaceChar(c)) c = pread(); int sgn = 1; if (c == '-') { sgn = -1; c = pread(); } int res = 0; do { if (c == ',') { c = pread(); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = pread(); } while (!isSpaceChar(c)); return res * sgn; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } static class Debug { PrintWriter out; boolean oj; long timeBegin; Runtime runtime; public Debug(PrintWriter out) { oj = System.getProperty("ONLINE_JUDGE") != null; this.out = out; this.timeBegin = System.currentTimeMillis(); this.runtime = Runtime.getRuntime(); } } }