#include using namespace std; #define C_BEGIN 1 #define C_END 3 #define TOWN 2 struct asd { int type; int place; int pop; int cid; }; long maximumPeople(vector p, vector x, vector y, vector r) { vector vv; for (int i = 0; i < p.size(); i++) { asd a; a.type = TOWN; a.pop = p[i]; a.place = x[i]; vv.push_back(a); } for (int i = 0; i < y.size(); ++i) { asd a; a.type = C_BEGIN; a.place = y[i]-r[i]; a.cid = i; vv.push_back(a); a.type = C_END; a.place = y[i]+r[i]; vv.push_back(a); } sort(vv.begin(), vv.end(), [](asd& a, asd& b) { if (a.place == b.place) return a.type < b.type; return a.place < b.place; }); long long happy_free = 0; map cloud_pop; { int clouds = 0; set ss; for (asd& aa : vv) { if (aa.type == C_BEGIN) { ss.insert(aa.cid); clouds++; } else if (aa.type == C_END) { clouds--; ss.erase(aa.cid); } else if (aa.type == TOWN) { if (clouds == 0) happy_free += aa.pop; if (clouds == 1) { cloud_pop[*ss.begin()] += aa.pop; } } } } long long max_cc = 0; for (auto e : cloud_pop) { max_cc = max(max_cc, e.second); } return happy_free + max_cc; } int main() { int n; cin >> n; vector p(n); for(int p_i = 0; p_i < n; p_i++){ cin >> p[p_i]; } vector x(n); for(int x_i = 0; x_i < n; x_i++){ cin >> x[x_i]; } int m; cin >> m; vector y(m); for(int y_i = 0; y_i < m; y_i++){ cin >> y[y_i]; } vector r(m); for(int r_i = 0; r_i < m; r_i++){ cin >> r[r_i]; } long result = maximumPeople(p, x, y, r); cout << result << endl; return 0; }