14346 - 2024_DS_Summer_Assignment1_pB   

Description

Given n 2D points, select k points such that the value of max(x1, x2, ..., xk) + max(y1, y2, ..., yk) is minimized. Here, (x1, y1), (x2, y2), ..., (xk, yk) are the coordinates of the selected k points.

Input

The first line contains two positive integers n and k.
The next n lines each contain two integers, representing the x and y coordinates of the n 2D points.

Constrain

  • 0 < k ≤ n ≤ 106
  • 0 < x1, x2, ..., xn ≤ 106
  • 0 < y1, y2, ..., yn ≤ 106

Output

Output the minimum value of max(x1, x2, ..., xk) + max(y1, y2, ..., yk).

Remember to print a ‘\n’ at the end of the output.

HINT

Select points (1, 6), (4, 8), and (5, 9) such that max(1, 4, 5) + max(6, 8, 9) = 14. This is the optimal selection.

Sample Input  Download

Sample Output  Download

Tags




Discuss