#include using namespace std; #define endl '\n' #define mod 1000000007 #define pb push_back #define ll long long int #define llu long long unsigned int #define mp make_pair #define ms(x, v) memset(x, v, sizeof x) #define fr(i, a, b) for(int i=a; i<=b; i++) #define fb(i, a, b) for(int i=a; i>=b; i--) int n,m; int pop[200001],loc[200001]; int cld[100001],range[100001]; int bins(int low,int high,int i) { while(low=(cld[i]-range[i])) high=mid; else low=mid+1; } if(loc[low]<(cld[i]-range[i])) return -1; return low; } void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition (int arr[], int low, int high) { int pivot = arr[high]; // pivot int i = (low - 1); // Index of smaller element for (int j = low; j <= high- 1; j++) { // If current element is smaller than or // equal to pivot if (arr[j] <= pivot) { i++; // increment index of smaller element swap(&arr[i], &arr[j]); swap(&pop[i],&pop[j]); } } swap(&arr[i + 1], &arr[high]); swap(&pop[i + 1], &pop[high]); return (i + 1); } void quickSort(int arr[], int low, int high) { if (low < high) { /* pi is partitioning index, arr[p] is now at right place */ int pi = partition(arr, low, high); // Separately sort elements before // partition and after partition quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; int hash[n]={0}; fr(i,0,n-1) cin>>pop[i]; fr(i,0,n-1) cin>>loc[i]; cin>>m; fr(i,0,m-1) cin>>cld[i]; fr(i,0,m-1) cin>>range[i]; quickSort(loc,0,n-1); fr(i,0,m-1) { int first=bins(0,n-1,i); if(first!=-1) { while(loc[first]<=(cld[i]+range[i])) { hash[first]++; first++; } } } int ans=0; fr(i,0,n-1) { if(!hash[i]) ans+=pop[i]; } int maxpop=INT_MIN; fr(i,0,m-1) { int first=bins(0,n-1,i); int temp=0; if(first!=-1) { while(loc[first]<=(cld[i]+range[i])) { if(hash[first]==1) temp+=pop[i]; first++; } if(temp>maxpop) maxpop=temp; } } ans+=maxpop; cout<