QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 128 MB 満点: 100 ハック可能 ✓

#16098. Wireless Network Transmitter Placement

統計

With the increasing popularity of smartphones, the demand for wireless networks is growing. A city has decided to provide wireless coverage in public places throughout the city.

Assume the city's layout is a grid formed by $129$ strictly parallel east-west streets and $129$ strictly parallel north-south streets, where the distance between adjacent parallel streets is a constant value of $1$. The east-west streets are numbered $0, 1, 2, \dots, 128$ from north to south, and the north-south streets are numbered $0, 1, 2, \dots, 128$ from west to east.

The intersections of east-west streets and north-south streets form junctions. The coordinate of the junction formed by the north-south street numbered $x$ and the east-west street numbered $y$ is $(x, y)$. Some junctions contain a certain number of public places.

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

For example, the figure below shows the coverage area of a wireless network transmitter with $d = 1$.

Now, the relevant government department plans to install a wireless network transmitter with a propagation parameter $d$. They would like you to help them find a suitable junction in the city as the installation site to maximize the number of covered public places.

Input

The first line contains an integer $d$, representing the propagation distance of the wireless network transmitter.

The second line contains an integer $n$, representing the number of junctions with public places.

The next $n$ lines each contain three integers $x, y, k$, separated by spaces, representing the coordinates $(x, y)$ of the junction and the number of public places at that junction. Each coordinate is given only once.

Output

Output a single line containing two integers separated by a space, representing the number of installation site options that cover the maximum number of public places, and the maximum number of public places that can be covered.

Examples

Input 1

1
2
4 4 10
6 6 20

Output 1

1 30

Constraints

For $100\%$ of the data, $1 \leq d \leq 20$, $1 \leq n \leq 20$, $0 \leq x \leq 128$, $0 \leq y \leq 128$, $0 < k \leq 1\,000\,000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.