#P7253. [BalticOI 2012] 城市烟花 (Day2)
[BalticOI 2012] 城市烟花 (Day2)
Description
This is a city with infinitely many grid-like streets. Some citizens live at the intersection points of the grid. (It is possible that two citizens live at the same place.)
Now you need to choose an intersection point between some vertical street and horizontal street as the place to set off fireworks. Citizens must come to either the horizontal street or the vertical street that contains this point to watch. At the same time, their distance to the fireworks location must not be less than . You need to choose a fireworks location to minimize the total moving distance of all citizens.
Input Format
The first line contains two integers , , representing the total number of citizens and the minimum distance, respectively.
The next lines each contain two integers , , meaning that this citizen lives at the intersection of horizontal street and vertical street .
Output Format
Output the minimum possible sum of moving distances.
7 2
3 -2
0 8
-4 8
-1 4
-2 13
-4 8
1 5
9
Hint
Sample Explanation
Note that there are two people living at the intersection of horizontal street and vertical street .
The optimal solution is to choose vertical street , and then the minimum total distance is .
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , .
Notes
Translated from BalticOI 2012 Day2 T1. Fireworks in RightAngleles.
Translated by ChatGPT 5
京公网安备 11011102002149号