#!/bin/python3 import sys from collections import namedtuple Town = namedtuple("town", "population clouds") def sunnyPeople(towns, clouds): mask = set() towns = towns.copy() for c in clouds: mask.update(set(range(c[0]-c[1], c[0]+c[1]+1))) #print(mask) for i in mask: towns.pop(i, None) #print(towns) return sum(map(lambda x: x.population, towns.values())) def maximumPeople(p, x, y, r): # Return the maximum number of people that will be in a sunny town after removing exactly one cloud. towns = dict(zip(x, p)) for i in towns: towns[i] = Town(towns[i], set()) clouds = set(zip(y, r)) for c in clouds: for xi in range(c[0]-c[1], c[0]+c[1]+1): if xi in towns: towns[xi].clouds.add(c) #list of towns that might be saved # cloud : {town, ...} possible = dict() for t in towns: if len(towns[t].clouds) == 1: possible.setdefault(list(towns[t].clouds)[0], set()).add(t) #uniquely covered population best_cloud = None best_pop = None for c in possible: c_pop = sum(map(lambda x: towns[x].population, possible[c])) if best_cloud is None or c_pop > best_pop: best_cloud = c best_pop = c_pop #print(best_cloud) if best_cloud is not None: clouds.remove(best_cloud) else: clouds = list(clouds)[1:] towns[t] return(sunnyPeople(towns, clouds)) if __name__ == "__main__": n = int(input().strip()) p = list(map(int, input().strip().split(' '))) x = list(map(int, input().strip().split(' '))) m = int(input().strip()) y = list(map(int, input().strip().split(' '))) r = list(map(int, input().strip().split(' '))) result = maximumPeople(p, x, y, r) print(result)