USGS's seismometers have just detected a major earthquake! Emergency response teams need a quick estimate of the number of people affected. Write a program to compute this estimate.
Your program receives 2 inputs. The first is the details of the earthquake itself. The earthquake modeled as a line segment along which the earth ruptured, along with the critical distance from the fault within which damage could be expected. The second input is a list of the location and population of cities in the area. Your program should compute the number of people living in the affected area, that is the sum of the population of all cities within the critical distance of the fault segment.
Input
First a line describing the earthquake, containing the x,y coordinates of the start and end points of the fault, plus the critical distance. The format is A_x A_y B_x B_y D
. For example:
3.0 3.0 7.0 4.0 2.5
encodes the fault extending from (3.0,3.0) to (7.0,4.0) and a critical distance of 2.5.
Second, one line per city in the area, containing the x,y coordinates of the city and its population. For example:
1.0 1.0 2500
5.0 7.0 8000
3.0 4.0 7500
9.0 6.0 3000
4.0 2.0 1000
Output
The number of people living in the affected area. For the above example only the third and fifth cities are in the danger area, so the output would be
8500
Shortest code wins.
Example 2
0.0 0.0 10.0 0.0 5.0
5.0 4.0 10000
5.0 -4.0 1000
5.0 6.0 100
11.0 2.0 10
-4.0 4.0 1
generates
11010
8500.0
be ok for the example? And could we maybe get some more testcases? \$\endgroup\$