#P10025. 「HCOI-R1」孤独的 sxz
「HCOI-R1」孤独的 sxz
Background
sxz is not good at socializing, so he usually likes to sit in secluded places. Today, sxz came to the cafeteria. He still wants to find a secluded seat, making the sum of Manhattan distances from him to all other people as large as possible.
Problem Description
The seats in the cafeteria can be seen as a rectangle divided into an grid, with length and width . Each cell ( are integers) is a seat.
Now there are already people in the cafeteria. The -th person sits at . sxz wants to find a seat such that the sum of Manhattan distances from this seat to the people is maximized. Please help him find this maximum value, and leave the rest to sxz.
Suppose sxz sits at point . Then the sum of Manhattan distances between him and the people is .
Obviously, sxz cannot sit at the same position as any of the people.
Input Format
The first line contains three integers .
The next lines: the -th line contains two integers .
Output Format
Only one line with one integer, describing this value. Note that it may be very large.
2 5 3
1 1
1 3
1 4
10
7 4 9
1 4
2 3
4 1
6 2
7 1
5 2
3 4
1 1
7 4
38
Hint
Sample Explanation 1
The best position is . The Manhattan distances to the people are , , and , respectively.
Constraints
This problem uses bundled testdata.
- Subtask 0 (15 pts): .
- Subtask 1 (25 pts): .
- Subtask 2 (20 pts): .
- Subtask 3 (40 pts): No special constraints.
For all data, , $1 \leq k \leq \min\{4 \times 10^5, n \times m - 1\}$, , , and it is guaranteed that all are pairwise distinct.
Translated by ChatGPT 5