#include #include #include #include #include #include #include using namespace std; const int MAXN = 2e5 + 5; int pop[MAXN], x[MAXN]; int l[MAXN], r[MAXN], cnt[MAXN]; multimap mymap; int main() { int n, m; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &pop[i]); } for (int i = 1; i <= n; i++) { scanf("%d", &x[i]); mymap.insert(make_pair(x[i], i)); } scanf("%d", &m); for (int i = 1; i <= m; i++) { scanf("%d", &l[i]); } for (int i = 1; i <= m; i++) { int cur; scanf("%d", &cur); r[i] = l[i] + cur; l[i] = l[i] - cur; auto r_border = mymap.upper_bound(r[i]); for (auto it = mymap.lower_bound(l[i]); it != r_border;) { cnt[it->second]++; if (cnt[it->second] > 1) it = mymap.erase(it); else it++; } } vector cities; vector pref; cities.push_back(-(int)1e9); pref.push_back(0); for (auto it : mymap) { cities.push_back(it.first); pref.push_back(pref.back() + pop[it.second]); } int sz = (int)pref.size(); long long ans = 0; for (int i = 1; i <= m; i++) { int left = lower_bound(cities.begin(), cities.end(), l[i]) - cities.begin(); int right = upper_bound(cities.begin(), cities.end(), r[i]) - cities.begin(); ans = max(ans, pref[right - 1] - pref[left - 1]); } for (int i = 1; i <= n; i++) if (cnt[i] == 0) ans += pop[i]; printf("%lld\n", ans); return 0; }