#include using namespace std; typedef long long ll; typedef double ld; const int INF = (int) 1e9 + 1e6; const ll LINF = (ll) 1e18 + 1e9; const ld EPS = (ld) 1e-10; const ll MOD = (ll) 1e9 + 7; #define sz(x) (int) (x).size() #define mp(x, y) make_pair(x, y) #define pb push_back #define all(x) (x).begin(), (x).end() #define lb(s, t, x) (int) (lower_bound(s, t, x) - s) #define ub(s, t, x) (int) (upper_bound(s, t, x) - s) #define rep(i, f, t) for (auto i = f; i < t; ++(i)) #define per(i, f, t) for (auto i = (f); i >= (t); --(i)) ll power(ll x, ll y, ll mod = MOD) { if (y == 0) { return 1; } if (y & 1) { return power(x, y - 1, mod) * x % mod; } else { ll tmp = power(x, y / 2, mod); return tmp * tmp % mod; } } template bool mini(A &x, const B &y) { if (y < x) { x = y; return true; } return false; } template bool maxi(A &x, const B &y) { if (y > x) { x = y; return true; } return false; } void run(); #define TASK "" int main() { #ifdef LOCAL if (strlen(TASK) > 0) { cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl; } #endif #ifndef LOCAL if (strlen(TASK)) { freopen(TASK ".in", "r", stdin); freopen(TASK ".out", "w", stdout); } ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #endif cout << fixed << setprecision(12); run(); return 0; } // == SOLUTION == // const int N = (int) 2e5 + 123; int n, m; int p[N], x[N]; int y[N], r[N]; unordered_map f; void add(int x, int y) { for (; x < INF; x += x & (-x)) f[x] += y; } ll get(int r) { ll res = 0; for (; r > 0; r -= r & (-r)) if (f.count(r)) res += f[r]; return res; } void run() { cin >> n; rep(i, 0, n) { cin >> p[i]; } rep(i, 0, n) { cin >> x[i]; } cin >> m; rep(i, 0, m) { cin >> y[i]; } rep(i, 0, m) { cin >> r[i]; } f.reserve(N * 30); rep(i, 0, m) { int L = y[i] - r[i]; int R = y[i] + r[i]; add(max(1, L), +1); add(R + 1, -1); } vector> cool; ll have = 0; rep(i, 0, n) { ll t = get(x[i]); if (t == 0) have += p[i]; if (t == 1) cool.pb({x[i], p[i]}); } f.clear(); for (auto &it : cool) { add(it.first, it.second); } ll ans = have; rep(i, 0, m) { int L = y[i] - r[i]; int R = y[i] + r[i]; maxi(ans, have + get(R) - get(L - 1)); } cout << ans << "\n"; }