#K60372. Optimal Disaster Relief Center Placement
Optimal Disaster Relief Center Placement
Optimal Disaster Relief Center Placement
You are given a grid of size W by H and a list of disaster zones represented by their coordinates. The disaster zones are located on the grid using 0-indexed coordinates. Your task is to determine the optimal location to place a Disaster Relief Center (DRC) such that the maximum Manhattan distance from the DRC to any disaster zone is minimized.
The Manhattan distance between two points \((x_1, y_1)\) and \((x_2, y_2)\) is defined as:
[ D = |x_1 - x_2| + |y_1 - y_2| ]
One effective strategy is to choose the location by taking the midpoint (using integer division) between the minimum and maximum values of the disaster zones' coordinates. That is, if \(min_x\) and \(max_x\) are the minimum and maximum x-coordinates and \(min_y\) and \(max_y\) are the minimum and maximum y-coordinates among the disaster zones, then the optimal coordinates \((X, Y)\) can be computed as:
[ X = \left\lfloor \frac{min_x + max_x}{2} \right\rfloor, \quad Y = \left\lfloor \frac{min_y + max_y}{2} \right\rfloor ]
Note that the grid dimensions W and H are provided for context but the optimal position is determined solely based on the positions of the disaster zones.
inputFormat
The input is read from standard input in the following format:
- The first line contains two integers W and H representing the width and height of the grid respectively.
- The second line contains an integer N, the number of disaster zones.
- The next N lines each contain two integers x and y which denote the coordinates of a disaster zone.
All coordinates are 0-indexed and satisfy \(0 \le x < W\) and \(0 \le y < H\).
outputFormat
Print two integers X and Y separated by a space. These integers represent the coordinates of the optimal location for the Disaster Relief Center. The output should be written to standard output.
## sample5 5
3
0 0
4 0
2 4
2 2
</p>