#include using namespace std; #define DB(x){if(DEBUG)cerr<<__LINE__<<" "<<#x<<" " <=(b);--i) #define ALL(x) (x).begin(),(x).end() templatevoid MAX(X&a,Y b){a=(a>=b?a:b);} templatevoid MIN(X&a,Y b){a=(a<=b?a:b);} typedef long long LL;typedef long double LD; int DEBUG=0,MULTI=0,GCJ=0; #define VV vector struct solver_t;solver_t *solver; struct solver_t { struct town_t { LL pop; LL loc; bool operator < (const town_t &rhs) const {return loc < rhs.loc; } }; struct cloud_t { LL loc; LL rad; LL idx; LL left; LL right; bool operator < (const cloud_t &rhs) const {return left < rhs.left; } }; void solve() { int N ; cin >> N; VV town(N); REP (i, N) cin >> town[i].pop; REP (i, N) cin >> town[i].loc; sort(ALL(town)); int M ; cin >> M; VV cloud(M); REP (m, M) cloud[m].idx = m; REP (m, M) cin >> cloud[m].loc; REP (m, M) cin >> cloud[m].rad; REP (m, M) cloud[m].left = cloud[m].loc - cloud[m].rad; REP (m, M) cloud[m].right = cloud[m].loc + cloud[m].rad; VV > OPER; REP (m, M) OPER.push_back( {cloud[m].left, 0, (int)m }); REP (m, M) OPER.push_back( {cloud[m].right + 1, 1, (int)m }); sort( ALL(OPER) ); OPER.push_back( { (LL)1e18, 0, 0} ); set clouds; map per_cloud; int op = 0; LL no_cov = 0; REP (n, N) { int loc = town[n].loc; for (;OPER[op][0] <= loc;op++) { if (OPER[op][1] == 0) clouds.insert(OPER[op][2]); if (OPER[op][1] == 1) clouds.erase(OPER[op][2]); } if (clouds.size() == 0) no_cov += town[n].pop; if (clouds.size() == 1) { int cloud_id = *clouds.begin(); per_cloud[cloud_id] += town[n].pop; } } LL res = 0; for (auto el : per_cloud) MAX( res, el.second ); cout << res + no_cov << "\n"; } void gen() {} void brute() {} }; int main(int argc,char** argv){ FOR(i,1,argc-1)for(int j=0;argv[i][j];j++)if(argv[i][j]=='.')freopen(argv[i],"r",stdin); FOR(i,1,argc-1)if(argv[i]==string("q"))DEBUG=1<<30; FOR(i,1,argc-1)if(argv[i]==string("gen")){(solver=new solver_t())->gen();exit(0);} FOR(i,1,argc-1)if(argv[i]==string("brute")){(solver=new solver_t())->brute();exit(0);} ios::sync_with_stdio(false),cin.tie(0); cout.setf(ios::fixed),cout.precision(10);int t;if(MULTI||GCJ)cin>>t;else t=1; FOR(i,1,t){if(DEBUG)cerr<<__LINE__<<" "<solve(); }return 0; }