#include using namespace std; #define fRead(x) freopen(x,"r",stdin) #define fWrite(x) freopen (x,"w",stdout) #define LL long long #define ULL unsigned long long #define ff first #define ss second #define pb push_back #define INF 2e16 #define PI acos(-1.0) #define mk make_pair #define pii pair #define pll pair #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define min4(a,b,c,d) min(a,min(b,min(c,d))) #define max4(a,b,c,d) max(a,max(b,max(c,d))) #define SQR(a) ((a)*(a)) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define ROF(i,a,b) for(int i=a;i>=b;i--) #define REP(i,b) for(int i=0;i city,cloud; LL top[N],cum[N],n,m,seg[N],s=0; vectoralone; int main() { cin >> n; city.resize(n); REP(i,n)cin >> city[i].second; REP(i,n)cin >> city[i].first; SORT(city); cin >> m; cloud.resize(m); REP(i,m)cin >> cloud[i].first; REP(i,m)cin >> cloud[i].second; REP(i,m) { LL l = cloud[i].first - cloud[i].second; LL r = cloud[i].first + cloud[i].second; auto it = lower_bound(city.begin(),city.end(),mk(l,0LL)); auto pt = upper_bound(city.begin(),city.end(),mk(r,2000000000LL)); if(pt == city.begin())continue; pt--; LL L = it - city.begin(); LL R = pt - city.begin(); if(L > R)continue; cum[L]++; cum[R+1]--; } LL pop = 0; REP(i,n) { s += cum[i]; seg[i] = s; if(s == 1){ alone.push_back(mk(city[i].first,i)); }else if(s == 0){ pop += city[i].second; } } LL ans = pop; REP(i,m) { LL l = cloud[i].first - cloud[i].second; LL r = cloud[i].first + cloud[i].second; auto it = lower_bound(alone.begin(),alone.end(),mk(l,0LL)); LL calc = 0; while(it!=alone.end() and city[it->second].first <= r){ calc += city[it->second].second; it++; } ans = max(ans,pop + calc); } cout << ans << "\n"; }