QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 512 MB 總分: 100

#8902. Video Surveillance

统计

The security of a shopping center is maintained by a video surveillance system. A program on the security guard's computer displays video feeds from several cameras. This program is organized as follows: the screen shows a rectangular grid consisting of $h$ rows and $w$ columns. Each cell can either be empty or display an image from one of the cameras. To manage the layout of the images in the program, the security officer can use the "left", "right", "up", and "down" buttons.

The "left" button moves the image from each cell to the cell to its left. The image from the leftmost cell in each row moves to the rightmost cell of that row.

The "right", "up", and "down" buttons work in a similar way. The "right" button moves the image from each cell to the cell to its right, with images from the rightmost cell in each row moving to the leftmost cell of that row. The "up" button moves the image from each cell to the cell above it, with images from the top row moving to the bottom row. The "down" button moves the image from each cell to the cell below it, with images from the bottom row moving to the top row.

Rows in the grid are numbered from top to bottom, and columns are numbered from left to right. The cell at the intersection of row $r$ and column $c$ is denoted as $(r, c)$.

Below is a grid with 3 rows, 4 columns, and three cells containing images at coordinates $(1, 1)$, $(2, 4)$, and $(3, 3)$. It also shows where these images move when each of the four buttons is pressed.

The security guard prefers the cells on the monitor that contain camera images to be arranged as compactly as possible. We define the compactness of the images as the minimum area of a sub-rectangle of the grid that contains all the displayed images. Note that the buttons can be used to change the compactness. For example, the left part of the figure below shows an arrangement of images that has a compactness of 12. If you press the "right" button once and the "up" button once, the compactness of the images will become 4.

You are given a grid containing $k$ cells with images. Calculate the minimum compactness that can be achieved using the "left", "right", "up", and "down" buttons, as well as the minimum number of button presses required to achieve this.

Input

The first line contains three integers $h$, $w$, and $k$ — the dimensions of the grid and the number of cells with images ($1 \le h, w \le 10^9$; $1 \le k \le 100\,000$).

Each of the following $k$ lines contains two integers $r_i$ and $c_i$ — the coordinates of the cell containing an image ($1 \le r_i \le h$; $1 \le c_i \le w$). It is guaranteed that all $k$ cells are distinct.

Output

Output two integers — the minimum compactness of the image arrangement that can be achieved using the buttons, and the minimum number of button presses required to achieve this compactness.

Subtasks

Subtask Points Additional Constraints Required Subtasks
1 5 $k = 1$
2 10 $k = 2$
3 29 $h = 1$
4 11 $h, w \le 50$ 3
5 15 $h, w \le 1\,000$ 4
6 6 $h, w \le 200\,000$ 4, 5
7 24 No additional constraints 1–6

Examples

Input 1

1 10 3
1 5
1 7
1 2

Output 1

6 0

Input 2

3 4 3
1 1
3 4
1 4

Output 2

4 2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.