Codeforces596C. Wilbur and Points

C. Wilbur and Points
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 and0 ≤ 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 from1 to n. In order to make the numberingaesthetically pleasing, Wilbur imposes the condition that if some point (x,y) gets number i, then all (x',y') from the set, such thatx' ≥ 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 is1, 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'sspecial value as s(x, y) = y - x. Now he gives Wilbur somew1,w2,...,wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets numberi has it's special value equal to wi, that iss(xi, yi) = yi - xi = wi.

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 integersx 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 and0 ≤ y' ≤ y, are also present in the input.

The last line of the input contains n integers. Thei-th of them is wi ( - 100 000 ≤ wi ≤ 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 thats(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".

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

Examples
Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Output
YES
0 0
1 0
2 0
0 1
1 1
Input
3
1 0
0 0
2 0
0 1 2
Output
NO
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 andyi - xi = wi.

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 is0, 1, 2. Therefore, the answer does not exist.

題意:給出N個點,有給出N個價值,點i的價值爲yi-xi,每個點給一個標記值1~N,當已知xi,yi的標記值爲i,那麼當又一個點的x和分別大於等於xi,yi時,這個點的標記值不能小於i。問存不存在排列能湊出給出的N個價值。

思路:老實說我不太清楚題意,WA了兩發後根據錯的數據修改一下排序過了。我是先把已知的點按他們的價值升序排,若價值相等就按y升序排,若y也相等就按x升序排。

給出的N個價值按升序排,價值相等按序號升序排。排完後一 一 對比,若出現不點的價值不同於對應數據給的價值則no,對比後再遍歷一邊點,若出現xi,yi均小於xi-1,yi-1的話no,

最後就可以再排序將結果輸出了。

發佈了153 篇原創文章 · 獲贊 4 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章