Codeforces Round #331 (Div. 2)-C-Wilbur and Points(STL容器)

来源:互联网 发布:表白 网页 源代码 php 编辑:程序博客网 时间:2024/06/08 12:22
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 (xy) 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 (xy) 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 (00), (01), (10) and (11), there are two aesthetically pleasing numberings. One is 1234 and another one is 1324.

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 w1w2,..., 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 (xy) 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
52 00 01 01 10 10 -1 -2 1 0
output
YES0 01 02 00 11 1
input
31 00 02 00 1 2
output
NO
Note

In the first sample, point (20) gets number 3, point (00) gets number one, point (10) gets number 2, point (11) gets number 5 and point (01) 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 is012. Therefore, the answer does not exist.


题意:给你n个坐标,每个坐标的权值为y[i]-x[i]。然后给你n个权值,问你能否找到

相应坐标,若不能找到输出NO,否则输出YES,并输出方案(任意一种)。

题目有一个坑点就是假如x[i]>=x[j] && y[i]>=y[j]时,id[i]必须大于id[j]。

题解:直接用STL容器模拟即可。对于坑点,直接用pair+set搞搞就好了。

#include<set>      #include<map>         #include<stack>                #include<queue>                #include<vector>        #include<string>     #include<time.h>    #include<math.h>                #include<stdio.h>                #include<iostream>                #include<string.h>                #include<stdlib.h>        #include<algorithm>       #include<functional>        using namespace std;                #define ll long long          #define inf 1000000000           #define mod 1000000007                #define maxn  205000    #define lowbit(x) (x&-x)                #define eps 1e-9  map<int,pair<int,int> >q;map<int,set<pair<int,int> > >p;int main(void){int n,i,a,b,x,y;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d%d",&a,&b);p[b-a].insert(make_pair(a,b));}for(i=1;i<=n;i++){scanf("%d",&x);if(p[x].empty()){printf("NO\n");return 0;}q[i]=*p[x].begin();p[x].erase(p[x].begin());}for(i=2;i<=n;i++){x=q[i].first;y=q[i].second;int xx=q[i-1].first;int yy=q[i-1].second;if(xx>=x && yy>=y){printf("NO\n");return 0;}}printf("YEs\n");for(i=1;i<=n;i++)printf("%d %d\n",q[i].first,q[i].second);return 0;}


阅读全文
0 0
原创粉丝点击