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;
}

【26.67%】【codeforces 596C】Wilbur and Points的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【26.09%】【codeforces 579C】A Problem about Polyline

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【23.26%】【codeforces 747D】Winter Is Coming

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 797C】Minimal string

    [题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...

  7. 【codeforces 510C】Fox And Names

    [题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...

  8. 【codeforces 807B】T-Shirt Hunt

    [题目链接]:http://codeforces.com/contest/807/problem/B [题意] 你在另外一场已经结束的比赛中有一个排名p; 然后你现在在进行另外一场比赛 然后你当前有一 ...

  9. 【codeforces 67A】Partial Teacher

    [题目链接]:http://codeforces.com/problemset/problem/67/A [题意] 给一个长度为n-1的字符串; 每个字符串是'L','R','='这3种字符中的一个; ...

随机推荐

  1. sass和less,优秀的前端样式预处理器

    身为切图界的一员,或者说在前端界打滚了一段日子的你.会慢慢地发现.如今的css编写已经不能满足自己的效率. 假设有更强大的框架,让你的css更灵活和更easy复用和维护,那该多好啊.非常明显,这个早已 ...

  2. js进阶 14-4 $.get()方法和$.post()方法如何使用

    js进阶 14-4 $.get()方法和$.post()方法如何使用 一.总结 一句话总结:$.get(URL,callback); $.post(URL,data,callback); callba ...

  3. 从大整数乘法的实现到 Karatsuba 快速算法

    Karatsuba 快速乘积算法是具有独特合并过程(combine/merge)的分治算法(Karatsuba 是俄罗斯人).此算法主要是对两个整数进行相乘,并不适用于低位数(如 int 的 32 位 ...

  4. SpringMVC,采用的是SpringJDBC

    上一次复习搭建了SpringMVC+Mybatis,这次搭建一下SpringMVC,采用的是SpringJDBC,没有采用任何其他的ORM框 架,SpringMVC提供了一整套的WEB框架,所以如果想 ...

  5. vue项目对axios的全局配置

    标准的vue-cli项目结构(httpConfig文件夹自己建的): api.js: //const apiUrl = 'http://test';//测试域名,自己改成自己的 const apiUr ...

  6. 全端project师必备技能汇总

    首先,看一张前端知识结构图:  (原文: ithomer) 图片的形式具有诸多的不便.缺失源图的我们.无法为此图贡献些什么,随着时间的迁移,也许有些技术点会发生改变.所以有了这个GitHub项目.我们 ...

  7. spark原理介绍 分类: B8_SPARK 2015-04-28 12:33 1039人阅读 评论(0) 收藏

    1.spark是一个基于内存计算的开源的集群计算系统,目的是让数据分析更加快速.因此运行spark的机器应该尽量的大内存,如96G以上. 2.spark所有操作均基于RDD,操作主要分成2大类:tra ...

  8. js进阶 12-6 如何获取正在发生事件的名字和是哪个元素在发生事件

    js进阶 12-6 如何获取正在发生事件的名字和是哪个元素在发生事件 一.总结 一句话总结:event.type 描述事件的类型.        event.target 触发该事件的 DOM 元素. ...

  9. -bash: /usr/local/mysql/scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory

    安装 MySQL 初始化时,报错如下: [root@hcdb1 ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/m ...

  10. 10、V4L2摄像头获取单幅图片测试程序(MMAP模式)

    #include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h> ...