#K65892. Optimal Distribution Center

    ID: 32298 Type: Default 1000ms 256MiB

Optimal Distribution Center

Optimal Distribution Center

You are given the coordinates of several warehouses. Your task is to determine the optimal coordinates \( (R, S) \) for establishing a distribution center such that the total sum of distances from the center to all warehouses is minimized. In this problem, the optimal point is determined by taking the median of the x-coordinates and the median of the y-coordinates of the warehouses. More formally, let there be \( N \) warehouses with coordinates \( (A_i, B_i) \). Sort the x-coordinates and y-coordinates separately. Then, the optimal location is given by \( (x_{\lceil N/2 \rceil}, y_{\lceil N/2 \rceil}) \).

Note: Although the original minimization target refers to the sum of Euclidean distances, this method of taking medians is typically optimal when considering the Manhattan distance. In this problem, use the median approach as described.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer \( T \), the number of test cases.
  • For each test case, the first line contains an integer \( N \) representing the number of warehouses.
  • This is followed by \( N \) lines, each containing two space-separated integers \( A \) and \( B \) denoting the coordinates of a warehouse.

You may assume that \( N \ge 1 \) for each test case.

outputFormat

For each test case, output a single line on stdout containing two space-separated integers \( R \) and \( S \) which represent the optimal coordinates of the distribution center.

## sample
1
3
1 1
2 2
3 3
2 2

</p>