#P16293. [蓝桥杯 2026 省 Java A 组] 奇怪的地图

[蓝桥杯 2026 省 Java A 组] 奇怪的地图

Problem Description

Xiao Lan is traveling in a certain country. The cities in this country are arranged on a hexagonal grid, as shown in the figure. Each hexagon in the figure represents a city.

:::align{center} :::

If two cities share a common edge, then Xiao Lan can move from one city to the other in one step.

For any two cities, if it takes at least kk steps to walk from one city to the other, then the distance between these two cities is defined as kk. In other words, the distance here is the minimum number of steps between the two cities.

Each city can be represented by a unique coordinate (x,y)(x, y). Its meaning is: starting from the city with coordinate (0,0)(0, 0), first walk xx steps along the XX direction, then walk yy steps along the YY direction, and you will reach that city.

Now you are given the coordinates of nn cities. You need to find, among these nn cities, the distance between the two cities that are farthest apart.

Input Format

The first line contains a positive integer nn, indicating the number of cities given.

The next nn lines each contain two integers xi,yix_i, y_i, representing the coordinates of the ii-th city.

Output Format

Output one line containing one integer, representing the distance between the two farthest cities among the given nn cities.

4
0 -1
-1 -1
2 2
4 2
5

Hint

Sample Explanation

These four cities are exactly the four cities marked in the figure.

Among them, the farthest pair of cities is (−1,−1)(-1, -1) and (4,2)(4, 2). Starting from (−1,−1)(-1, -1), you can first walk 3 steps in the upper-right direction to reach (2,2)(2, 2); then walk 2 steps along the positive direction of the XX axis to reach (4,2)(4, 2).

The shortest distance between these two cities is 5, so the answer is 5.

Constraints

For 50%50\% of the testdata, n≤3000n \le 3000.

For all testdata, 2≤n≤3×1052 \le n \le 3 \times 10^5, ∣xi∣,∣yi∣≤109|x_i|, |y_i| \le 10^9.

Translated by ChatGPT 5