PIZZALOC - Pizza Location

Our friend Picko is very reach and he wants to open lots of restaurants with delivery. The main food will be, of course, pizza. He has certain number of potential locations for the restaurants, and he knows the locations of the solitairs with lots of people which will often be his customers. Delivery of each restaurant will cover all the solitairs in given radius.

Picko can open only limited number of restaurants, and he wants that restaurants on the locations which will cover maximal number of people in solitairs.

Write a program that will calculate maximal number of people which we can cover with delivery.

Input

In the first line of the input file there are two integers K and R, separated with space, number of restaurants and radius of delivery, 1 ≤ K ≤ 10, 1 ≤ R ≤ 500.

In the second line there is integer M, number of locations, K ≤ M ≤ 20.

In each of the next M lines there are two integer X and Y, separated with space, coordinates of each location, -1000 ≤ X,Y ≤ 1000.

In the next line there is integer N, number of solitairs, 1 ≤ N ≤ 100.

In each of the next N lines there are three integers X, Y and S, separated with space, X and Y are coordinates of each solitaire, and S is number of people in that solitaire, -1000 ≤ X,Y ≤ 1000, 1 ≤ S ≤ 100.

We consider that solitaire is in radius of some restaurant if distance between them is less or equal to R. There are no two locations of restaurants on the same place.

Output

In only line of the output file we have to write maximal number from the text above.

Sample

pizza.in 
2 2 
3 
1 0 
4 0 
7 0 
4 
0 0 1 
3 0 7 
5 0 9 
8 0 1 
 
pizza.out 
18 

pizza.in 
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 
 
pizza.out 
12 

pizza.in 
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 
 
pizza.out 
17 


Được gửi lên bởi:psetter
Ngày:2009-04-08
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO PERL6 PYPY RUST SED
Nguồn bài:COI 03

hide comments
2021-05-27 18:03:00
Tham khảo: https://vnspoj.github.io/problems/PIZZALOC
2020-02-24 04:27:53
cay quá khai báo mảng thiếu phần tử nên bị WA :(
2019-09-26 03:38:13
Xin chào các fan hâm mộ.
duonght_pro_xinhgainhathemattroi_:)
2019-08-12 12:19:19
tự tin 1 đấm AC :))
2019-03-14 09:02:35
https://youtu.be/G2HVHCiAYMI
say oh yeah
2018-12-25 04:27:09
Thử dùng bitset khởi tạo trước xem mỗi nhà hàng phục vụ được khác hàng nào thì AC :v
CYB
2016-11-27 02:32:07
Đệ Quy + BIT -> AC
sub chục lần đủ các kiểu mới AC
2016-11-03 15:40:06
Bài này áp dụng backtrack. Tuy nhiên, có một chú ý là mình lưu lại những ngôi nhà mà tại mỗi vị trí, nhà hàng có thể phục vụ vào một mảng => sẽ không bị time limit.
http://thuattoan.phamvanlam.com/spoj-com-thuat-toan-bai-pizzaloc-pizza-location/
2016-07-12 10:52:46
long long=TLE
int=AC????
2016-06-19 18:16:04 trần thị quỳnh châu
Bài này đặt cận thế nào hả mọi người. Em bị quá thời gian
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.