using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long maximumPeople(long[] population, long[] cityLocation, long[] cloudClocation, long[] cloudSize) { Dictionary townsIndex = new Dictionary(); Dictionary townCloudCount = new Dictionary(); for (long x = 0; x < cityLocation.Length; x++) { townsIndex.Add(cityLocation[x], x); townCloudCount.Add(cityLocation[x], 0); } for (long x = 0; x < cloudClocation.Length; x++) for (long y = cloudClocation[x] > cloudSize[x] ? cloudClocation[x] - cloudSize[x] : 0; y <= cloudClocation[x] + cloudSize[x]; y++) { if (townCloudCount.ContainsKey(y)) townCloudCount[y]++; } var singleCloudCities = new HashSet(townCloudCount.Where(x => x.Value == 1).Select(x => x.Key)); var clouds = new List(); for (long x = 0; x < cloudClocation.Length; x++) { long pop = 0; for (long y = cloudClocation[x] > cloudSize[x] ? cloudClocation[x] - cloudSize[x] : 0; y <= cloudClocation[x] + cloudSize[x]; y++) { if (singleCloudCities.Contains(y)) pop += population[townsIndex[y]]; } if (pop > 0) clouds.Add(pop); } return (clouds.Count > 0 ? clouds.Max() : 0) + townCloudCount.Where(x => x.Value == 0).Sum(x => population[townsIndex[x.Key]]); } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] p_temp = Console.ReadLine().Split(' '); long[] p = Array.ConvertAll(p_temp, Int64.Parse); string[] x_temp = Console.ReadLine().Split(' '); long[] x = Array.ConvertAll(x_temp, Int64.Parse); int m = Convert.ToInt32(Console.ReadLine()); string[] y_temp = Console.ReadLine().Split(' '); long[] y = Array.ConvertAll(y_temp, Int64.Parse); string[] r_temp = Console.ReadLine().Split(' '); long[] r = Array.ConvertAll(r_temp, Int64.Parse); long result = maximumPeople(p, x, y, r); Console.WriteLine(result); } }