Codeforces Round 331 (Div. 2)
C
Wilbur and Points
Codeforces
1700
原题
← BD →
翻译中…

Wilbur is playing with a set of $*n*$ points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point ($*x*$, $*y*$) belongs to the set, then all points ($*x*'$, $*y*'$), such that $0 ≤ *x*' ≤ *x*$ and $0 ≤ *y*' ≤ *y*$ also belong to this set.

翻译中…

Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from $1$ to $*n*$. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point ($*x*$, $*y*$) gets number $*i*$, then all ($*x*'$,$*y*'$) from the set, such that $*x*' ≥ *x*$ and $*y*' ≥ *y*$ must be assigned a number not less than $*i*$. For example, for a set of four points ($0$, $0$), ($0$, $1$), ($1$, $0$) and ($1$, $1$), there are two aesthetically pleasing numberings. One is $1$, $2$, $3$, $4$ and another one is $1$, $3$, $2$, $4$.

翻译中…

Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as $*s*(*x*, *y*) = *y* - *x*$. Now he gives Wilbur some $*w*_{1}$, $*w*_{2}$,..., $*w*_{*n*}$, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number $*i*$ has it's special value equal to $*w*_{*i*}$, that is $*s*(*x*_{*i*}, *y*_{*i*}) = *y*_{*i*} - *x*_{*i*} = *w*_{*i*}$.

翻译中…

Now Wilbur asks you to help him with this challenge.

翻译中…

Input

翻译中…

The first line of the input consists of a single integer $*n*$ ($1 ≤ *n* ≤ 100 000$) — the number of points in the set Wilbur is playing with.

翻译中…

Next follow $*n*$ lines with points descriptions. Each line contains two integers $*x*$ and $*y*$ ($0 ≤ *x*, *y* ≤ 100 000$), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point ($*x*$, $*y*$) is present in the input, then all points ($*x*'$, $*y*'$), such that $0 ≤ *x*' ≤ *x*$ and $0 ≤ *y*' ≤ *y*$, are also present in the input.

翻译中…

The last line of the input contains $*n*$ integers. The $*i*$-th of them is $*w*_{*i*}$ ($- 100 000 ≤ *w*_{*i*} ≤ 100 000$) — the required special value of the point that gets number $*i*$ in any aesthetically pleasing numbering.

翻译中…

Output

翻译中…

If there exists an aesthetically pleasant numbering of points in the set, such that $*s*(*x*_{*i*}, *y*_{*i*}) = *y*_{*i*} - *x*_{*i*} = *w*_{*i*}$, then print "YES" on the first line of the output. Otherwise, print "NO".

翻译中…

If a solution exists, proceed output with $*n*$ lines. On the $*i*$-th of these lines print the point of the set that gets number $*i*$. If there are multiple solutions, print any of them.

翻译中…

Note

翻译中…

In the first sample, point ($2$, $0$) gets number $3$, point ($0$, $0$) gets number one, point ($1$, $0$) gets number $2$, point ($1$, $1$) gets number $5$ and point ($0$, $1$) gets number $4$. One can easily check that this numbering is aesthetically pleasing and $*y*_{*i*} - *x*_{*i*} = *w*_{*i*}$.

翻译中…

In the second sample, the special values of the points in the set are $0$, $- 1$, and $- 2$ while the sequence that the friend gives to Wilbur is $0$, $1$, $2$. Therefore, the answer does not exist.

翻译中…

样例

Input #1
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output #1
YES
0 0
1 0
2 0
0 1
1 1
InputCopy OutputCopy
Input #2
3
1 0
0 0
2 0
0 1 2
Output #2
NO
InputCopy OutputCopy
题目信息
题号
596C
时间限制
2 s
内存限制
256 MB
标签
组合数学
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。