using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { struct range{ public long b; public long e; } static long maximumPeople(long[] p, long[] x, long[] y, long[] r) { // Return the maximum number of people that will be in a sunny town after removing exactly one cloud. List list = new List(); for (int i = 0; i < y.Length; i++){ range a; a.b = y[i] - r[i]; a.e = y[i] + r[i]; list.Add(a); } list.Sort((pair1, pair2) => pair1.b.CompareTo(pair2.b)); Array.Sort(x); bool[] v = new bool[x.Length]; long max = 0; for (int i = 0; i < list.Count; i++){ long pop = 0; for (int d = 0; d < x.Length; d++){ if (x[d] >= list[i].b || x[d] <= list[i].e){ pop += p[d]; v[d] = true; } } max = Math.Max(max, pop); } long sun = 0; for (int i = 0; i < v.Length; i++){ if (v[i] == false) sun += p[i]; } return sun + max; } 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); //population string[] x_temp = Console.ReadLine().Split(' '); long[] x = Array.ConvertAll(x_temp,Int64.Parse);//location of town int m = Convert.ToInt32(Console.ReadLine()); string[] y_temp = Console.ReadLine().Split(' '); long[] y = Array.ConvertAll(y_temp,Int64.Parse);//location of clouds string[] r_temp = Console.ReadLine().Split(' '); long[] r = Array.ConvertAll(r_temp,Int64.Parse);//range of clouds long result = maximumPeople(p, x, y, r); Console.WriteLine(result); } }