# Wilbur and Points

Codeforces Round #331 (Div. 2)

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 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.

Sample test(s)
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

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-4
#define MAXN (200000+10)
#define MAXM (1000000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 100000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
using namespace std;
struct Node{
int x, y, val, id, rec;
};
Node num1[MAXN], num2[MAXN];
bool cmp(Node a, Node b)
{
if(a.val != b.val)
return a.val < b.val;
else if(a.x != b.x)
return a.x < b.x;
else
return a.y < b.y;
}
bool cmp1(Node a, Node b)
{
if(a.val != b.val)
return a.val < b.val;
else
return a.id < b.id;
}
bool cmp2(Node a, Node b){
return a.id < b.id;
}

int main()
{
int n; Ri(n);
for(int i = 0; i < n; i++)
{
Ri(num1[i].x); Ri(num1[i].y);
num1[i].val = num1[i].y - num1[i].x;
num1[i].id = i;
}
sort(num1, num1+n, cmp);
for(int i = 0; i < n; i++)
{
Ri(num2[i].val);
num2[i].id = i;
}
sort(num2, num2+n, cmp1);
bool flag = true;
for(int i = 0; i < n; i++)
{
if(num1[i].val != num2[i].val)
{
flag = false;
break;
}
else
num2[i].rec = num1[i].id;
}
if(flag)
{
sort(num2, num2+n, cmp2);
sort(num1, num1+n, cmp2);
for(int i = 1; i < n; i++)
{
if(!(num1[num2[i].rec].x > num1[num2[i-1].rec].x || num1[num2[i].rec].y > num1[num2[i-1].rec].y))
{
flag = false;
break;
}
}
if(flag)
{
printf("YES\n");
for(int i = 0; i < n; i++)
printf("%d %d\n", num1[num2[i].rec].x, num1[num2[i].rec].y);
}
else
printf("NO\n");
}
else
printf("NO\n");
return 0;
}

• 本文已收录于以下专栏：

## 说说蛋疼的数据源

• baidu_34051990
• 2017年03月06日 18:02
• 98

## 一些比较蛋疼的翻译

2014-11-03    关于计算机术语的翻译这个问题，我一直在思考这个问题，我也一直在做笔记，希望能够凑足足够的资料的思考，对这个问题好好分析一下。 虽然我在谈论中英文术语翻译的事儿，在...
• cloudqiu
• 2017年02月10日 12:03
• 172

## 蛋疼的算法~~

• wangningyu
• 2010年04月13日 18:53
• 905

## js的一些蛋疼的问题

1. js 的放的位置 要正确，在服务器页面上，放body下面不执行……，一定要放在Form 表单上面或里面  2.前端可以有重名的函数 3.注册控件事件RegisterStartup...
• softuse
• 2016年10月11日 10:20
• 131

## 不到500行代码学完shell基本语法知识

• qingtianweichong
• 2016年11月13日 21:49
• 749

## C++蛋疼问题终结（一）自然对界

• gingss
• 2014年08月30日 17:17
• 116

## win10 uwp 参考

• lindexi_gd
• 2016年02月20日 10:27
• 4789

## 蛋疼

#!/bin/bash echo -ne "\033[0;33m" cat                                   _oo0oo_                   ...
• syloke
• 2015年08月30日 20:12
• 179

## 蛋疼的任务

• wewe000
• 2010年08月12日 18:29
• 48

## 蛋疼的数据库！

• cory2012
• 2011年06月30日 16:53
• 63

举报原因： 您举报文章：用到蛋疼的sort 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)