#include #include #include #include #include #include #include using namespace std; struct Node { long long pos; int type, index; }; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n, m; scanf("%d", &n); vector p, x, y, r; unordered_map dict; for (int i = 0; i < n; i++) { int temp; scanf("%d", &temp); p.push_back(temp); } for (int i = 0; i < n; i++) { int temp; scanf("%d", &temp); x.push_back(temp); } scanf("%d", &m); for (int i = 0; i < m; i++) { int temp; scanf("%d", &temp); y.push_back(temp); } for (int i = 0; i < m; i++) { int temp; scanf("%d", &temp); r.push_back(temp); } vector pos; for (int i = 0; i < n; i++) { Node temp; temp.pos = x[i]; temp.type = 2; temp.index = i; pos.push_back(temp); } for (int i = 0; i < m; i++) { Node temp; temp.pos = y[i] - r[i]; temp.type = 1; temp.index = i; pos.push_back(temp); temp.pos = y[i] + r[i]; temp.type = 3; temp.index = i; pos.push_back(temp); } sort(pos.begin(), pos.end(), [](const Node& a, const Node& b){ return (a.pos < b.pos) || (a.pos == b.pos && a.type < b.type); }); long long sum = 0, ans = 0; unordered_set cur; for (const auto& iter : pos) { if (iter.type == 2) { if (cur.size() > 1) { continue; } if (cur.size() == 1) { dict[*(cur.begin())] += p[iter.index]; } else { sum += p[iter.index]; } } else if (iter.type == 1) { cur.insert(iter.index); } else { cur.erase(iter.index); } } for (const auto& iter : dict) { ans = max(ans, iter.second); } cout << sum + ans << endl; return 0; }