pizza
Our friend Vasile has become very rich and wants to open a chain of K pizzerias, which would take and deliver orders.
Vasile is considering M potential locations for his pizzerias. One pizzeria can provide for all the orders in its range of activity (a circular area of radius R, with the center at the restaurant's location).
It is a well-known fact that students are great pizza consumers, so Vasile considers them as being sure customers. For this reason Vasile has identified the locations of N student dorms, as well as the number of students in each dorm.
Vasile wants to choose K of the M possible locations for his pizzerias so that the total number of sure clients be as large as possible.
Task
Write a program that determines the maximum number of sure clients Vasile can count on.
Input Data
Line one of input file pizza.in contains two positive integers, K and R, separated by a space, representing the number of pizzerias Vasile wants to open, and respectively the range of each pizzeria.
The second line contains a positive integer M, representing the number of possible locations for pizzerias.
Each of the following M lines contains two positive integers, X and Y, separated by a space, representing the coordinates of a location (in abscise, ordinate order).
The following line contains a positive integer N, representing the number of student dorms.
Each of the following N lines contains information about a dorm, in the form of a set of three integers separated by a space, X Y S, with the meaning "at point having coordinates X, Y there is a student dorm in which S students live in".
Output Data
Output file pizza.out will contain a single line with the maximum number of sure clients Vasile can count on.
Restrictions
1 <= K <= 10
1 <= R <= 500
K <= M <= 20
All coordinates are integers, -1000 <= X,Y <= 1000
1 <= N <= 100
1 <= S <=100
We say that a dorm is in the range of a pizzeria if the distance from the dorm to the pizzeria is smaller than or equal to R.
There are no two locations having the same coordinates.
Examples
pizza.in | pizza.out | pizza.in | pizza.out |
2 2 3 1 0 4 0 7 0 4 0 0 1 3 0 7 5 0 9 8 0 1 |
18 | 2 2 3 -2 0 0 1 3 0 8 -3 1 1 -3 0 1 -3 -1 1 -2 -1 1 0 0 3 0 2 1 2 1 3 4 0 2 |
12 |
Time limit: 1.2 seconds/test
prof. Emanuela Cerchez
"Grigore Moisil" Iaşi IT High School
Contact:emanuela.cerchez@gmail.com