#C11274. Treasure Hunt: Collect All Treasures
Treasure Hunt: Collect All Treasures
Treasure Hunt: Collect All Treasures
You are given a starting position on a 2D grid and a list of treasures located at various coordinates on the grid. In one step, you can move to any position that is within the Chebyshev distance 1 (i.e. you may move diagonally as well as horizontally or vertically).
The task is to determine the minimum number of steps required to collect all the treasures. The number of steps needed to reach a given treasure from the starting position is defined mathematically as:
[ \text{steps} = \max\left(|x_i - x_0|,; |y_i - y_0|\right) ]
You are given multiple test cases. For each test case, compute and output the minimum number of steps required.
inputFormat
The input is given via standard input.
The first line contains an integer T
— the number of test cases. Each test case is described as follows:
- The first line of each test case contains three integers:
x0
,y0
(the starting coordinates) andN
(the number of treasures). - Then follow
N
lines, each containing two integersx
andy
representing the coordinates of a treasure.
All input values are separated by spaces or newlines.
outputFormat
For each test case, output a single integer — the minimum number of steps required to collect all treasures.
Each result should be printed on its own line.
## sample2
0 0 3
-1 -1
1 2
3 3
-2 -2 2
1 1
-3 -3
3
3
</p>