import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static long maximumPeople(long[] p, long[] x, long[] y, long[] r) { // Return the maximum number of people that will be in a sunny town after removing exactly one cloud. int n=p.length; int m=y.length; int c=-1; long maxp=Integer.MIN_VALUE; int sunny[]=new int[n]; Arrays.fill(sunny,1); long sum=0l; long sum1=0l; long range1=0l,range2=0l; for(int i=0;i=range1&&x[j]<=range2){ sum=sum+p[j]; sunny[j]=0; } } if(sum>maxp){ maxp=sum; c=i; } } range2=y[c]+r[c]; range1=y[c]-r[c]; for(int i=0;irange2)) sum1+=p[i]; } maxp+=sum1; return maxp; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] p = new long[n]; for(int p_i = 0; p_i < n; p_i++){ p[p_i] = in.nextLong(); } long[] x = new long[n]; for(int x_i = 0; x_i < n; x_i++){ x[x_i] = in.nextLong(); } int m = in.nextInt(); long[] y = new long[m]; for(int y_i = 0; y_i < m; y_i++){ y[y_i] = in.nextLong(); } long[] r = new long[m]; for(int r_i = 0; r_i < m; r_i++){ r[r_i] = in.nextLong(); } long result = maximumPeople(p, x, y, r); System.out.println(result); in.close(); } }