#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip> #include<ctime> #include<complex> #include<functional> #include<climits> #include<cassert> #include<iterator> #include<unordered_set> #include<unordered_map> using namespace std; int n; vector<pair<int,int> > v; int m; vector<int> tmp; vector<int> star[200002]; vector<int> en[200002]; set<int> ava; long long int cnt[200002]; int main() { cin >> n; for (int i = 0; i < n; i++) { int a; scanf("%d", &a); v.push_back(make_pair(-1,a) ); } for (int i = 0; i < n; i++) { int x; scanf("%d", &x); v[i].first = x; } cin >> m; for (int i = 0; i < m; i++) { int a; scanf("%d", &a); tmp.push_back(a); } sort(v.begin(), v.end()); for (int i = 0; i < m; i++) { int r; scanf("%d", &r); int lef = tmp[i] - r; int b = lower_bound(v.begin(), v.end(), make_pair( lef,-1)) - v.begin(); int rig = tmp[i] + r; int b2 = upper_bound(v.begin(), v.end(), make_pair( rig,INT_MAX )) - v.begin(); star[b].push_back(i); en[b2].push_back(i); } long long int ans = 0; for (int i = 0; i < v.size(); i++) { for (int el : star[i]) { ava.insert(el); } for (int el : en[i]) { ava.erase(el); } if (ava.size() == 0) { ans += v[i].second; } if (ava.size() == 1) { cnt[(*ava.begin())] += v[i].second; } } ans += *max_element(cnt, cnt + m); printf("%lld\n", ans); return 0; }