QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB

#23488. Magic Colored Paper

الإحصائيات

We want to take a rectangular sheet of magic colored paper with horizontal and vertical grid lines spaced $1$ unit apart

and cut it horizontally and vertically into smaller rectangular pieces.

Initially, one white sheet is given.

Thereafter, whenever a point is given, cut a piece according to the following rules.

(1) If the given point lies in a white piece, cut along the horizontal line through that point.

Both resulting pieces turn black.

(2) If the given point lies in a black piece, cut along the vertical line through that point.

Both resulting pieces turn white.

Given the width and height of the white magic paper and an ordered sequence of points inside it,

write a program that, after all the cuts are made according to the rules above, finds the area of the largest piece

and the area of the smallest piece.

No two input points lie on the same horizontal or vertical line.

Furthermore, no input point lies on the boundary of the original sheet.

The width and height of the paper are positive integers.

The position of each point used to cut the paper is given by two integers: its horizontal distance

and its vertical distance from the lower-left corner of the original uncut sheet.

For example, point 1 in the figures below is at $(5,4)$.

Suppose a sheet of width $8$ and height $7$ is to be cut at points

$(5,4)$, $(2,3)$, $(3,1)$, $(7,6)$, $(6,2)$, given in this order.

First, the first point cuts the sheet into two black pieces as in Figure 1.

problem_23488_cfd143e7033d82497b68c092e511c119.png

Figure 1

Next, the second point divides the lower black piece in Figure 1 into two white pieces as in Figure 2.

problem_23488_c853c5bf50df689b385dd80e4c731f46.png

Figure 2

Cutting at all the remaining points in the same way produces Figure 3.

In this case, the largest piece has area $21$ and the smallest piece has area $3$.

problem_23488_0366376e97a2bd2637b58388d5e30a2b.png

Figure 3

Input

The first line contains two space-separated positive integers, the width and height of the paper.

Both dimensions are at most $40,000$.

The second line contains a positive integer $N$, the number of points used to cut the paper. It holds that $N\le 30000$.

From the third through the last line, the cutting points are given in order, one per line.

Each position is given as the horizontal distance followed by the vertical distance, separated by a space.

Output

On the first line, print the areas of the largest and smallest pieces, in that order, separated by a space.

Examples

Input 1

8 7 
5
5 4 
2 3 
3 1 
7 6 
6 2

Output 1

21 3

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.