Under construction

Still being built. Things may change

Pizza Delivery

Time limit1sMemory limit128 MB

Summary
Choose at most K of M candidate sites to maximize the total population within radius R, counting each building once even if covered multiple times.
Level

Medium6 of 10

Topics
Combinatorics, Brute force, Geometry
Solved
No attempts yet

Problem

Picko wants to open pizza restaurants that provide delivery. There are M candidate restaurant locations, and there are N residential buildings with known populations.

A restaurant can deliver to every residential building whose Euclidean distance from that restaurant is at most R. Picko may open at most K restaurants at the candidate locations. If a building is covered by more than one restaurant, its population is counted only once.

Compute the maximum number of people who can be covered by delivery.

Input

The first line contains two integers K and R, the maximum number of restaurants and the delivery radius (1 <= K <= 10, 1 <= R <= 500).

The second line contains an integer M, the number of candidate restaurant locations (K <= M <= 20).

Each of the next M lines contains two integers X and Y, the coordinates of one candidate location (-1000 <= X, Y <= 1000).

The next line contains an integer N, the number of residential buildings (1 <= N <= 100).

Each of the next N lines contains three integers X, Y, and S. Here, X and Y are the coordinates of a residential building, and S is the number of people living there (-1000 <= X, Y <= 1000, 1 <= S <= 100). A residential building is covered by a restaurant if the distance between them is at most R.

No two candidate restaurant locations have the same coordinates.

Output

Print one integer: the maximum number of people who can be covered by delivery.

Examples3

  1. Example 1

    Input
    2 2
    3
    1 0
    4 0
    7 0
    4
    0 0 1
    3 0 7
    5 0 9
    8 0 1
    
    Expected output
    18
    
  2. Example 2

    Input
    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
    
    Expected output
    12
    
  3. Example 3

    Input
    3 3
    5
    0 0
    1 6
    2 3
    6 6
    7 2
    8
    0 1 2
    0 5 3
    0 6 1
    1 0 1
    3 2 3
    3 6 2
    6 2 4
    8 6 3
    
    Expected output
    17