题库练习 The Hard Work of Paparazzi
← 上一题 下一题 →

A13801 | The Hard Work of Paparazzi

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are a paparazzi working in Manhattan.

Manhattan has $r$ south-to-north streets, denoted by numbers $1, 2,\ldots, r$ in order from west to east, and $r$ west-to-east streets, denoted by numbers $1,2,\ldots,r$ in order from south to north. Each of the $r$ south-to-north streets intersects each of the $r$ west-to-east streets; the intersection between the $x$ -th south-to-north street and the $y$ -th west-to-east street is denoted by $(x, y)$ . In order to move from the intersection $(x,y)$ to the intersection $(x', y')$ you need $|x-x'|+|y-y'|$ minutes.

You know about the presence of $n$ celebrities in the city and you want to take photos of as many of them as possible. More precisely, for each $i=1,\dots, n$ , you know that the $i$ -th celebrity will be at the intersection $(x_i, y_i)$ in exactly $t_i$ minutes from now (and he will stay there for a very short time, so you may take a photo of him only if at the $t_i$ -th minute from now you are at the intersection $(x_i, y_i)$ ). You are very good at your job, so you are able to take photos instantaneously. You know that $t_i < t_{i+1}$ for any $i=1,2,\ldots, n-1$ .

Currently you are at your office, which is located at the intersection $(1, 1)$ . If you plan your working day optimally, what is the maximum number of celebrities you can take a photo of?

输入格式

The first line of the input contains two positive integers $r, n$ ( $1\le r\le 500$ , $1\le n\le 100,000$ ) – the number of south-to-north/west-to-east streets and the number of celebrities.

Then $n$ lines follow, each describing the appearance of a celebrity. The $i$ -th of these lines contains $3$ positive integers $t_i, x_i, y_i$ ( $1\le t_i\le 1,000,000$ , $1\le x_i, y_i\le r$ ) — denoting that the $i$ -th celebrity will appear at the intersection $(x_i, y_i)$ in $t_i$ minutes from now.

It is guaranteed that $t_i<t_{i+1}$ for any $i=1,2,\ldots, n-1$ .

输出格式

Print a single integer, the maximum number of celebrities you can take a photo of.

输入输出样例

输入 #1
10 1
11 6 8
输出 #1
0
输入 #2
6 9
1 2 6
7 5 1
8 5 5
10 3 1
12 4 4
13 6 2
17 6 6
20 1 4
21 5 4
输出 #2
4
输入 #3
10 4
1 2 1
5 10 9
13 8 8
15 9 9
输出 #3
1
输入 #4
500 10
69 477 122
73 186 235
341 101 145
372 77 497
390 117 440
494 471 37
522 300 498
682 149 379
821 486 359
855 157 386
输出 #4
3
C++ 编辑器
输入
输出