C. Wilbur and Points

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

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.

题解: 很容易想到贪心先构造出一组解,然后需要判断解的合法性,就是必须满足偏序(存在(x,y)的编号为i,则对于所有(a,b)的编号j,j>i,a>=x,b>=y),这个可以利用树状数组判可行解;

AC代码:

#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
typedef pair<int,int> P;
map<int,int> mp,tp;
int x[N],y[N],n,c[N];bool check() {for(auto e: tp) {if(e.second) return false;}return true;
}void update(int x,int val) {while(x <= n + 1) {if(c[x] > val) c[x] = val;x += x & -x;}
}int que(int x) {int s = INF;while(x > 0) {if(c[x] < s) s = c[x];x -= x & -x;}return s;
}bool solve() {for(int i = n - 1; i >= 0; i--) {if(que(x[i] + 1) <= y[i]) return false;else update(x[i] + 1,y[i]);}puts("YES");    for(int i = 0; i < n; i++) {printf("%d %d\n",x[i],y[i]);}return true;
}int main() {cin>>n;memset(c,0x3f,sizeof(c));for(int i = 0; i < n; i++) {int x,y;scanf("%d %d",&x,&y);tp[y - x]++;}for(int i = 0; i < n; i++) {int w;scanf("%d",&w);x[i] = abs(w) + mp[w];y[i] = mp[w];mp[w]++;tp[w]--;if(w > 0) swap(x[i],y[i]);}if(check() == false) puts("NO");else if(solve() == false) puts("NO");return 0;
}

C. Wilbur and Points(简单贪心加合法性判断)相关推荐

  1. [堆+贪心] CF596C. Wilbur and Points

    CF596C. Wilbur and Points 题意: 太难懂了.有一个平面点集,对集合中任意一点(x,y),满足以原点和(x,y)构成的矩形边上和内部的所有点也都在集合里. 现在要给点标号,为了 ...

  2. html canvas直线进度条,js+HTML5 canvas 实现简单的加载条(进度条)功能示例

    本文实例讲述了js+HTML5 canvas 实现简单的加载条(进度条)功能.分享给大家供大家参考,具体如下: www.jb51.net canvas实现加载条动画 /* * 获取canvas, ca ...

  3. wxpython中文教程_wxPython中文教程 简单入门加实例

    wxPython中文教程简单入门加实例 博客分类: Python 2 / Wxpython wxPythonPython编程浏览器脚本 wx.Window 是一个基类,许多构件从它继承.包括 wx.F ...

  4. 最简单的加载器免杀思路

    本文首发于先知社区:https://xz.aliyun.com/t/9385 这部分源代码开放:https://github.com/MrWQ/HanGuang 最简单的加载器免杀思路 将加载器的变量 ...

  5. 数仓(十)从0到1简单搭建加载数仓DWS层

    数仓(一)简介数仓,OLTP和OLAP 数仓(二)关系建模和维度建模 数仓(三)简析阿里.美团.网易.恒丰银行.马蜂窝5家数仓分层架构 数仓(四)数据仓库分层 数仓 (五) 元数据管理系统解析 数仓( ...

  6. base64编码 vba_【VBA研究】如何用Base64 编解码方法实现简单的加解密

    Base64编码的思想是是采用64个基本的ASCII码字符对数据进行重新编码,将数据变成字符串实现文本传输.由于编码简单,所以很容易实现,代码也是现成的.利用这个编码规则可以实现简单的加解密.编解码方 ...

  7. oracle触发器判断空值,oracle触发器加条件判断、dblink

    --新增基站同步给电池组信息 create or replace trigger a_b_test after insert or update or delete on BJLT.BASESTATI ...

  8. Python手机号合法性判断(列表和正则)

    Python手机号合法性判断(列表和正则) 注意:这里不对地区编码(第4-7位)和用户号码(第8-11位)进行合法性判断! 需要进行哪些判断: 1. 号码是否为11位 2. 号码是否全为数字 3. 号 ...

  9. 【偏门技巧】C语言编程实现对IPV4地址的合法性判断(使用正则表达式)

    C语言编程实现对IPV4地址的合法性判断(使用正则表达式) 有了解过我的朋友,可能有点印象,我在N年前的博客中,就写了这个主题,当时确实是工作中遇到了这个问题.本想着等工作搞完之后,就把这个问题的解决 ...

最新文章

  1. pythonif语句缩进_Python中多行IF语句缩进的代码样式?
  2. python中strip()的陷阱
  3. Android开发中高效的数据结构用SparseArray代替HashMap
  4. Java怎么学?在学Java的过程中要注意些什么呢?
  5. [算法笔记] 爬楼梯
  6. spring自动装配依赖包_解决Spring自动装配中的循环依赖
  7. 在WordPress文章中插入表格的四种方法,史上最全
  8. js 对象数组常用操作 我用到的
  9. alsa的动态库安装在哪里_Linux链接库一(动态库,静态库,库放在什么路径下)...
  10. 11届蓝桥杯青少年组C++全国赛高级组 六.编程实现:求阶乘(python3实现)
  11. 云原生开发者须具备的1+N技能,开启第二曲线
  12. js 二叉树图形_在线生成二叉树(基于EaselJS(canvas))
  13. golang实现四种排序(快速,冒泡,插入,选择)
  14. 人工智能在医疗领域的应用
  15. txt unicode 前加 0xFF 0xFE
  16. WPS如何给公式加上右边序号
  17. altium summer 9导入orcad dsn文件的方法
  18. Truffle Unbox failed问题解决方法
  19. 华为上机英文数字翻译
  20. PPP协议和MAC地址、IP地址及ARP协议三者之间的关系(3.2)

热门文章

  1. cocos creator(12)
  2. 判断手机音量大小,做出提醒
  3. 用nginx的stream转发tcp/udp请求
  4. 笔试强训48天——day29
  5. 汇编 eax test jnz jz 等组合连用的总结
  6. Python学习记录——英文名修改成标准格式
  7. RobotFrameWork(二)Ride简单使用及快捷键
  8. 谷歌浏览器插件开发之 manifest.json 配置说明
  9. 谈谈VR游戏中的性能优化
  10. STL 常用容器(1)--string