#P2038. [NOIP 2014 提高组] 无线网络发射器选址

[NOIP 2014 提高组] 无线网络发射器选址

Description

With the increasing popularity of smartphones, the demand for wireless networks is growing. A certain city decides to cover public places with a wireless network.

Assume the city layout is a grid formed by 129129 east-west streets and 129129 north-south streets, and the distance between any two adjacent parallel streets is a constant 11. The east-west streets are numbered 0,1,21280,1,2 \dots 128 from north to south, and the north-south streets are numbered 0,1,21280,1,2 \dots 128 from west to east.

Intersections are formed where an east-west street meets a north-south street. The intersection of the north-south street numbered xx and the east-west street numbered yy has coordinates (x,y)(x, y). Some intersections have a certain number of public places.

Due to budget constraints, only one large wireless network transmitter can be installed. Its coverage area is a square centered at the installation point with side length 2d2d. The coverage includes the square’s boundary.

Now the authorities plan to install a transmitter with parameter dd. Please help them find a suitable intersection in the city as the installation location to maximize the number of public places covered.

Input Format

The first line contains an integer dd, the coverage parameter of the wireless network transmitter.

The second line contains an integer nn, the number of intersections that have public places.

The next nn lines each contain three integers x,y,kx, y, k separated by a space, representing the intersection coordinates (x,y)(x, y) and the number of public places at that intersection. Each coordinate appears at most once.

Output Format

Output one line containing two integers separated by a space: the number of installation locations that achieve the maximum coverage of public places, and the maximum number of public places covered.

1
2
4 4 10
6 6 20
1 30

Hint

For 100%100\% of the testdata, $1 \leq d \leq 20, 1 \leq n \leq 20, 0 \leq x \leq 128, 0 \leq y \leq 128, 0 < k \leq 10^6$.

Translated by ChatGPT 5