#include #include #include #include using namespace std; int main() { int towns,clouds; vector town_population, town_coordinates, cloud_coordinates, cloud_range; map townM, cloudM; cin >> towns; for(int i = 0; i < towns; i++){ int temp = 0; cin >> temp; town_population.push_back(temp); } for(int i = 0; i < towns; i++){ int temp = 0; cin >> temp; town_coordinates.push_back(temp); } for(int i = 0; i < towns; i++){ townM[town_coordinates[i]] = town_population[i]; } cin >> clouds; for(int i = 0; i < clouds; i++){ int temp = 0; cin >> temp; cloud_coordinates.push_back(temp); } for(int i = 0; i < clouds; i++){ int temp = 0; cin >> temp; cloud_range.push_back(temp); } for(int i = 0; i < clouds; i++){ cloudM[cloud_coordinates[i]] = cloud_range[i]; } vector bannedCoordinates; int maxPopulation = 0; int maxCloud = 0; int result = 0; for(pair cloud : cloudM){ int localPopulation = 0; for(int j = cloud.first - cloud.second; j < cloud.first + cloud.second; j++){ bannedCoordinates.push_back(j); localPopulation += townM[j]; } if(localPopulation > maxPopulation){ maxPopulation = localPopulation; maxCloud = cloud.first; } } for(int banned : bannedCoordinates){ if(!(banned >= (maxCloud - cloudM[maxCloud]) && banned <= (maxCloud + cloudM[maxCloud]))) townM[banned] = 0; } for(pair town: townM) result += town.second; cout << result; return 0; }