import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { long pop,coord,sum; 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; Solution obj[]=new Solution[n]; for(int i=0;i(){ public int compare(Solution c,Solution d) { return (int)c.coord-d.coord; } }); obj[0].sum=obj[0].pop; for(int i=1;i=0&&floor=0) curr1=obj[floor-1].sum; } else if(floor+1=0&&ceil=0) { end=ceil-1; curr2=obj[ceil-1].sum; } } for(int pp=start;pp<=end;pp++) if(pop1[pp]!=-1) tot+=pop1[pp]; if(curr2-curr1>=0) make[i]=curr2-curr1; max1=Math.max(max1,make[i]); } return (popu-tot)+max1; } static int floorSearch(Solution arr[], int low, int high, long x) { // If low and high cross each other if (low > high) return -1; // If last element is smaller than x if (x >= arr[high].coord) return high; // Find the middle point int mid = (low+high)/2; // If middle point is floor. if (arr[mid].coord == x) return mid; // If x lies between mid-1 and mid if (mid > 0 && arr[mid-1].coord <= x && x < arr[mid].coord) return mid-1; // If x is smaller than mid, floor // must be in left half. if (x < arr[mid].coord) return floorSearch(arr, low, mid - 1, x); // If mid-1 is not floor and x is // greater than arr[mid], return floorSearch(arr, mid + 1, high, x); } static int ceilSearch(Solution arr[], int low, int high, long x) { int mid; /* If x is smaller than or equal to the first element, then return the first element */ if(x <= arr[low].coord) return low; /* If x is greater than the last element, then return -1 */ if(x > arr[high].coord) return -1; /* get the index of middle element of arr[low..high]*/ mid = (low + high)/2; /* low + (high - low)/2 */ /* If x is same as middle element, then return mid */ if(arr[mid].coord == x) return mid; /* If x is greater than arr[mid], then either arr[mid + 1] is ceiling of x or ceiling lies in arr[mid+1...high] */ else if(arr[mid].coord < x) { if(mid + 1 <= high && x <= arr[mid+1].coord) return mid + 1; else return ceilSearch(arr, mid+1, high, x); } /* If x is smaller than arr[mid], then either arr[mid] is ceiling of x or ceiling lies in arr[mid-1...high] */ else { if(mid - 1 >= low && x > arr[mid-1].coord) return mid; else return ceilSearch(arr, low, mid - 1, x); } } 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(); } }