time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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 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 w1, w2,…, wn, 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 wi, that is s(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 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 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 that s(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 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.

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 and yi - 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 is 0, 1, 2. Therefore, the answer does not exist.

【题目链接】:http://codeforces.com/contest/596/problem/C

【题解】





题中所给的y-x这个特殊值;其实就是如上,约束这些点在y-x=wi这条线上;

而题中所给的条件转换一下可以理解为;

对于任意(x,y);如果x’<=x && y’<=y;则(x’,y’)的序号要在(x,y)这个点之前;

最后所给的要求序列;

相当于我们要在y-x=wi这条线段上选一个点放在序列的相应位置;

那我们要怎么选呢?



肯定要从上图上的这些圆圈圈中的点开始选(即从线的左下角开始往右上角依次选);

现在假设我们选过的点都标为红色;

然后w=1;

则我们要选如下这个点



那我们能选这个这个点吗?

答案是不行;

因为在这个蓝点的正下方有一个点(1,1)还没被选;

如果我们先选了那个蓝点;必然下面这个点会在这个蓝点的序号之后(所有的点都会出现,所以下面那个点是肯定会在后面选的);

但是下面那个点的横坐标1<=1,且纵坐标1<=2;这个点是肯定要在这个蓝点之前被选的;【还记的我们转换成的条件吗:对于任意(x,y);如果x’<=x && y’<=y;则(x’,y’)的序号要在(x,y)这个点之前;】

这就说明序列不合法;

因为我们是按照直线从左下往右上选的;而且每次都只选一个点;所以我们可以在选一个点(x,y)的时候先判断(x-1,y)和(x,y-1)有没有被选(边界就不用判断了);如果其中有一个点没被选;则不满足条件;

(我们可以在遇到w的时候,看看y-x=w这条线上从左下到右上的第一个没被选的点是啥(记录这条线上被选过的点的最右上那个点的横坐标即可),然后判断一下x-1,y和y,x-1有没有被加入balabalba一下就可以过了);



【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long using namespace std; //const int MAXN = x;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
map <int,int> dic;
map <int,int> maxx;
map <pair <int,int>,int> pre; int n;
vector <pair <int,int> > ans; void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
for (int i = 1;i <= n;i++)
{
int x,y;
rei(x);rei(y);
int temp = y-x;
dic[temp]++;
}
for (int i =-100000;i <= 0;i++)
maxx[i] = -i;
for (int i = 1;i <= n;i++)
{
int t;
rei(t);
int x,y;
x = maxx[t];y = x+t;
ans.push_back(make_pair(x,y));
if (x-1>=0 && !pre[make_pair(x-1,y)])
{
puts("NO");
return 0;
}
if (y-1>=0 && !pre[make_pair(x,y-1)])
{
puts("NO");
return 0;
}
pre[make_pair(x,y)] = 1;
dic[t]--;
maxx[t]++;
}
for (int i = -100000;i <= 100000;i++)
if (dic[i]!=0)
{
puts("NO");
return 0;
}
puts("YES");
for (int i = 0;i <= n-1;i++)
printf("%d %d\n",ans[i].first,ans[i].second);
return 0;
}

最新文章

  1. Object-c 类方法和实例方法的区别和联系
  2. HttpURLConnection发送POST请求(可包含文件)
  3. Java for LeetCode 160 Intersection of Two Linked Lists
  4. js上传和预览图片
  5. Linux Shell编程变量赋值和引用
  6. hdu4355 三分
  7. 常用的ASCII码对照表
  8. Java C# .net 和 C C++ 跨平台的区别
  9. 常用的HTML富文本编译器UEditor、CKEditor、TinyMCE、HTMLArea、eWebEditor、KindEditor简介
  10. 《机器学习实战》之一:knn(python代码)
  11. Adding a custom jar as a maven dependency
  12. tesseract编译错误:fatal error: allheaders.h: No such file or directory
  13. 在word 2010中采用EndNote X7插入引用
  14. Qt 编程指南 4 单行编辑控件
  15. windows下用python转换markdown到html
  16. React 组件间通信
  17. 【hdoj_1133】Buy the Ticket(卡特兰数+大数)
  18. Lepus_天兔的安装
  19. VC中CDC与HDC的区别以及二者之间的转换
  20. ML.NET---.NET下的机器学习引擎(简介)

热门文章

  1. 洛谷——U10206 Cx的治疗
  2. 微信支付v2开发(7) 告警通知
  3. 微信支付v2开发(5) 订单查询
  4. Android 解决RecyclerView删除Item导致位置错乱的问题
  5. win8.1 “服务器运行失败”的解决方法
  6. HDU 1166 敌兵布阵 树状数组||线段树
  7. 【Codeforces Round #442 (Div. 2) A】Alex and broken contest
  8. u-boot分析1:Nandflash、Norflash启动
  9. TableView相关属性
  10. [Angular] Learn How To Use ng-template Inputs