P29284 [洛谷] [KMOI R1] Military Operation
提高-
题目描述

Problem Background

$$\blue{They are coming.}$$

$$\purple{Assemble the troops, eliminate them, not a single one left.}$$

$$\blue{Yes, sir!}$$

Problem Description

The situation at the border of Meow Planet has become increasingly tense, leading to border conflicts. General Xiao Yuan of the Meow Planet military immediately launches a military operation against Planet Y.

The entire universe can be considered as a Cartesian coordinate system, with the coordinates of cities $1, 2, \dots, n$ being $(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)$.

General Xiao Yuan commands several fleets (it can be understood that his military strength is infinite) stationed at the border fortress, city $1$. His fleets will move as follows:

  • If a fleet is at coordinates $(x, y)$, then one day later it can move to $(x-1, y+2)$, $(x+1, y+2)$, $(x+2, y+1)$, $(x-2, y+1)$, $(x-1, y-2)$, $(x+1, y-2)$, $(x+2, y-1)$, or $(x-2, y-1)$.

There is also an asteroid belt surrounding the area. When a fleet's coordinates $(x, y)$ satisfy $x \le 0$, $y \le 0$, $x > m$, or $y > m$, the fleet will collide with the asteroid belt. This is something General Xiao Yuan wants to avoid.

Now, General Xiao Yuan plans to attack cities $2, 3, \dots, n$. Each time, he will dispatch a fleet from a previously occupied city (including city $1$) to city $i$ and attack it. The next day after the fleet's arrival, city $i$ will be occupied.

Specifically, General Xiao Yuan will not dispatch another fleet while one fleet is on its way to attack or attacking a city. However, he can immediately dispatch another fleet on the same day after occupying a city.

General Xiao Yuan wants to know the minimum time required to occupy all the cities.

The order of attacks does not have to follow the sequence $2, 3, \dots, n$.

Input Format

The first line contains two integers $n$ and $m$, representing the number of cities and the range of the asteroid belt, respectively.

The next $n$ lines each contain two positive integers $(x_i, y_i)$, representing the coordinates of city $i$. It is guaranteed that $1 \le x_i, y_i \le m$.

Output Format

An integer $ans$, representing the minimum time required.

Sample Input and Output

Sample Input #1

2 20
1 1
1 3

Sample Output #1

3

Sample Input #2

3 150
1 2
2 4
4 3

Sample Output #2

4

Sample Input #3

10 10
1 4
2 3
2 6
3 6
10 3
1 5
4 2
5 3
2 8
9 2

Sample Output #3

23

Sample Input #4

See attached example4.in

Sample Output #4

See attached example4.out

Notes

Sample 1 Explanation:

The fleet moves to position $(3, 2)$ on the first day, arrives at city $2$ on the second day, and occupies city $2$ on the third day. A total of 3 days are spent.

Sample 2 Explanation:

The fleet arrives at city $2$ on the first day, occupies city $2$ on the second day, arrives at city $3$ on the third day, and occupies city $3$ on the fourth day. A total of 4 days are spent.

Data Range

This problem uses Subtask-based testing.

Subtask Number Test Point Range $n$ $m$ Special Property Score
1 1-2 $1 \le n \le 7$ $4 \le m \le 7$ None 10
2 3-7 $1 \le n \le 200$ $4 \le m \le 70$ None 25
3 8-9 $1 \le n \le 150$ $4 \le m \le 150$ Yes 15
4 10-20 $1 \le n \le 2000$ $4 \le m \le 150$ None 50

Special Property: For every $1 \le i \le n-1$, $x_i = x_{i+1}$.

Data strictly ensures that no two cities have the same coordinates.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 20 1 1 1 3
样例输出
3