#include using namespace std; long maximumPeople(vector>p,vector>y) { // Return the maximum number of people that will be in a sunny town after removing exactly one cloud. sort(p.begin(),p.end()); sort(y.begin(),y.end()); long int psize=p.size(); long int min=p[0].second; long int max=p[psize-1].second; long int ysize=y.size(),i,j,indexi=0,indexj=0; long int tot=0; int flg=0; for(i=psize-1;i>=0;i--) { for(j=0;j=y[j].first-y[j].second)&&(p[i].second<=y[j].first+y[j].second)) { if(flg==0) {flg=1; indexi=i; indexj=j;} break; } } if(j==ysize) { tot+=p[i].first; } } long int res=tot+p[indexi].first; return res; } int main() { int n; cin >> n; vector> p(n); for(int p_i = 0; p_i < n; p_i++){ cin >> p[p_i].first; } for(int x_i = 0; x_i < n; x_i++){ cin >> p[x_i].second; } int m; cin >> m; vector> y(m); for(int y_i = 0; y_i < m; y_i++){ cin >> y[y_i].first; } for(int r_i = 0; r_i < m; r_i++){ cin >> y[r_i].second; } long result = maximumPeople(p,y); cout << result << endl; return 0; }