#include using namespace std; #define FORI(s,n) for (int i = s; i < n; i++) #define FORJ(s,n) for(int j = s; j < n; j++) #define FORK(s,n) for (int k = s; k < n; k++) #define ROFI(s,n) for (int i = n-1; i >= 0; i++) typedef vector vi; typedef unsigned long long ull; using ll = long double; using vvi = vector; using pii = pair; using vs = vector; using ss = set; using vl = vector; long maximumPeople(vector ppl, vector p_pos, vector c_pos, vector r) { long n = ppl.size (); multimap>> clouds; unordered_map towns; FORI ((long) 0, c_pos.size ()) { clouds.insert (make_pair (max (c_pos[i] - r[i], 0L), make_pair (min (c_pos[i] + r[i] + 1L, n), make_pair (c_pos[i], r[i])))); } FORI (0, n) towns[p_pos[i]] = ppl[i]; long cp, cr; ull max_ = 0; for (auto cloud = clouds.begin (); cloud != clouds.end (); ++cloud) { long a, b, c, d; a = cloud->first; b = cloud->second.first; c = cloud->second.second.first; d = cloud->second.second.second; auto nextc = next (cloud); ull t = 0; int i = a; while (i <= b) { if (nextc == clouds.end () || i < nextc->first) { auto town = towns.find (i); if (town != towns.end ()) { t += town->second; } i++; } else if (i <= nextc->second.first) { // do nothing i++; } else { // greater than nextc++; } } if (t > max_) { cp = c; cr = d; } } for (auto cloud = clouds.begin (); cloud != clouds.end (); ++cloud) { long c, d; c = cloud->second.second.first; d = cloud->second.second.second; if (c == cp && d == cr) { clouds.erase (cloud); break; } } ull sum = 0; for (auto town : towns) { long pos = town.first; long ppl = town.second; bool valid = true; for (auto cloud : clouds) { long a = cloud.first; long b = cloud.second.first; if (a <= pos && pos <= b) { valid = false; break; } } if (valid) sum += ppl; } return sum; } 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; }