#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) x.begin() , x.end() #define fi first #define se second #define pb push_back #define umax( x , y ) x = max( x , (y) ) #define umin( x , y ) x = min( x , (y) ) #define For( i , a ) for(int i=1;i<=a;i++) #define ort (b+s)/2 #define y2 asrwjaelkf #define y1 asseopirwjaelkf #define set multiset using namespace std; inline int read() { int res = 0 ;int neg ; while(true){char ch = getchar();if(ch>='0' && ch<='9' || ch=='-'){if(ch=='-') neg = -1;else neg = 1 , res = ch-'0';break;} } while(true){char ch = getchar();if(ch>='0' && ch<='9') res*=10 , res+=ch-'0';else break;} return res*neg; } typedef long long Lint; typedef double db; typedef pair ii; typedef pair dd; typedef pair ddd; typedef pair iii; typedef pair i4; const int maxn = 300120; const int maxm = 1000020; const int MOd = 1e9 + 7; const int K = 400; int a, b, Y[maxn], R[maxn]; ii ar[maxn]; ii bs[maxn]; int H[maxn]; Lint pre[maxn]; int val[maxn]; Lint cur; bool comp( const ii &a, const ii &b ) { if( (a.fi/K) == (b.fi/K) ) return a.se < b.se; return a.fi < b.fi; } void add( int x, int t ) { if( val[x] == 1 ) cur += t*ar[x].se; } int main() { //freopen("asd.in","r",stdin); //freopen("out.txt","w",stdout); scanf("%d",&a); for(int i=1;i<=a;i++) { scanf("%d",&ar[i].se); } for(int i=1;i<=a;i++) scanf("%d",&ar[i].fi); sort( ar+1, ar+1+a ); scanf("%d",&b); for(int i=1;i<=b;i++) scanf("%d",&Y[i]); for(int i=1;i<=b;i++) scanf("%d",&R[i]); for(int i=1;i<=b;i++) { bs[i].fi = lower_bound( ar+1, ar+1+a, ii( Y[i]-R[i], 0 ) ) - ar; bs[i].se = upper_bound( ar+1, ar+1+a, ii( Y[i]+R[i], 1e9+5 ) ) - ar - 1; //printf("asd %d %d\n",bs[i].fi,bs[i].se); H[bs[i].fi]++; H[bs[i].se+1]--; } Lint ans = 0; int k = 0; for(int i=1;i<=a;i++) { k += H[i]; val[i] = k; pre[i] = pre[i-1] + ar[i].se; if( !k ) ans += ar[i].se; } sort( bs+1, bs+1+b, comp ); int l = 1, r = 0; Lint ans2 = 0; for(int i=1;i<=b;i++) { while( l < bs[i].fi ) add( l++, -1 ); while( l > bs[i].fi ) add( --l, 1 ); while( r < bs[i].se ) add( ++r, 1 ); while( r > bs[i].se ) add( r--, -1 ); umax( ans2, cur ); } //cout << ans << endl; //cout << ans2 << endl; cout << ans + ans2 << endl; return 0; }