cf C. Wilbur and Points (STL_vector)


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.

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 (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 andyi - 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 012. Therefore, the answer does not exist.



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=100000+100;
struct node
{
    int x;
    int y;
}a[maxn],qq[maxn];
bool cmp(node t1,node t2)
{
    if(t1.x<t2.x) return true;
    return false;
}
vector<node>vv[300000];
int b[maxn];
int main()
{
     ios::sync_with_stdio(false);  
    int n,i,j,t,ok;
    node t1,t2,t3;
    ok=1;
    cin>>n;
    for(i=1;i<=n;i++) {
        cin>>a[i].x>>a[i].y;
        t=a[i].y-a[i].x+100000;
        vv[t].push_back(a[i]);
    }
    for(i=1;i<=n;i++) {
        cin>>b[i];
        b[i]+=100000;
        t=b[i];
        sort(vv[t].begin(),vv[t].end(),cmp);
    }
    t=b[1];
    if(vv[t].empty()) {
        cout<<"NO"<<endl;
        return 0;
    }
    t1=vv[t].front();
    vv[t].erase(vv[t].begin());
    qq[1].x=t1.x;
    qq[1].y=t1.y;
    for(i=2;i<=n;i++) {
        t=b[i];
        if(vv[t].empty()) {
            ok=0;
            break;
        }
        t1=vv[t].front();
        vv[t].erase(vv[t].begin());
        if(qq[i-1].x>=t1.x && qq[i-1].y>=t1.y) {
            ok=0;
            break;
        }
        else {
            qq[i].x=t1.x;
            qq[i].y=t1.y;
        }
    }
    if(ok) {
        cout<<"YES"<<endl;
        for(i=1;i<=n;i++) cout<<qq[i].x<<" "<<qq[i].y<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值