#include #include #include using namespace std; int main(void){ int numTowns; int numClouds; int num; int totalCityPop = 0; int totalCloudyPop = 0; vector popCount; vector townLocations; vector cloudLocations; vector cloudRanges; vector cloudyTownPop; cin >> numTowns; for(int i = 0; i < numTowns; i++){ cin >> num; popCount.push_back(num); totalCityPop += num; } for(int i = 0; i < numTowns; i++){ cin >> num; townLocations.push_back(num); } cin >> numClouds; for(int i = 0; i < numClouds; i++){ cin >> num; cloudLocations.push_back(num); } for(int i = 0; i < numClouds; i++){ cin >> num; cloudRanges.push_back(num); } auto currTown = townLocations.begin(); auto cityLimits = townLocations.end(); /* Find total population of cloudy towns */ for(int i = 0; i < cloudLocations.size(); i++){ int westBorder = cloudLocations[i] - cloudRanges[i]; int eastBorder = cloudLocations[i] + cloudRanges[i]; /* Find first town that falls under cloud */ while(currTown != cityLimits && *currTown < westBorder){ currTown++; } /* Loop through all towns that fall under cloud */ while(currTown != cityLimits && westBorder <= *currTown && *currTown <= eastBorder){ cloudyTownPop.push_back(*currTown); currTown++; } /* Move on to next cloud */ if(currTown == cityLimits) break; } auto mostCloudyTown = max_element(cloudyTownPop.begin(),cloudyTownPop.end()); cloudyTownPop.erase(mostCloudyTown); /* Add remaining population of cloudy towns in the city */ for(int pop : cloudyTownPop) totalCloudyPop += pop; cout << totalCityPop - totalCloudyPop; return 0; }