#include #define MOD 1000000007 using namespace std; typedef long long ll; typedef pair ii; typedef pair ti; int main() { ios::sync_with_stdio(false); int n, m; cin >> n; int p[n], x[n]; for (int ctr1 = 0; ctr1 < n; ++ctr1) cin >> p[ctr1]; for (int ctr1 = 0; ctr1 < n; ++ctr1) cin >> x[ctr1]; cin >> m; int y[m], r[m]; ll to[m]; memset(to, 0, sizeof(to)); for (int ctr1 = 0; ctr1 < m; ++ctr1) { cin >> y[ctr1]; } for (int ctr1 = 0; ctr1 < m; ++ctr1) { cin >> r[ctr1]; } vector occ; for (int ctr1 = 0; ctr1 < m; ++ctr1) { occ.push_back(make_pair(make_pair(y[ctr1] - r[ctr1], -1), ctr1)); occ.push_back(make_pair(make_pair(y[ctr1] + r[ctr1], 1), ctr1)); } for (int ctr1 = 0; ctr1 < n; ++ctr1) { occ.push_back(make_pair(make_pair(x[ctr1], 0), ctr1)); } sort(occ.begin(), occ.end()); unordered_set clouds; ll rez = 0; for (int ctr1 = 0; ctr1 < occ.size(); ++ctr1) { if (occ[ctr1].first.second < 0) { clouds.insert(occ[ctr1].second); } if (occ[ctr1].first.second > 0) { clouds.erase(occ[ctr1].second); } if (occ[ctr1].first.second == 0) { if (clouds.size() == 0) rez += p[occ[ctr1].second]; if (clouds.size() == 1) to[*clouds.begin()] += p[occ[ctr1].second]; } } ll mx = 0; for (int ctr1 = 0; ctr1 < m; ++ctr1) mx = max(mx, to[ctr1]); cout << rez + mx <<'\n'; return 0; }