Codeforces Round #331 (Div. 2) C. Wilbur and Points

时间:2022-12-27 22:47:20
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
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.

昏了头,做的时候想太多了.

先把a[i].y-a[i].x的数存进一个vector然后对于每个D[I],依次判断。

比如:对于D[I],如果V[D[I]].size==0那么输出”NO“;

V[D[I]]内部是按照先x,y排序的。

最后再判断一遍是否合法;

 #include<bits/stdc++.h>

 using namespace std;
typedef long long ll; #define N 211111 struct node
{
int x,y,id;
node(int _x=,int _y=,int _z=)
{
x=_x;
y=_y;
id=_z;
}
}a[N];
int d[N],ans[N];
vector<node>b[N+N]; int cmp(node a,node b)
{
// min(a.x,a.y)<min(b.x,b.y);
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
} int main()
{
int n;
cin>>n;
for (int i=;i<=n;i++)
{
cin>>a[i].x>>a[i].y;
b[a[i].y-a[i].x+N].push_back(node(a[i].x,a[i].y,i));//要先+N,因为可能为负数
} for (int i=;i<=n;i++)
{
cin>>d[i];
d[i]+=N; if (b[d[i]].size()==)
{
cout<<"NO";
return ;
}
sort(b[d[i]].begin(),b[d[i]].end(),cmp);//每次都排序 是有点费时间
ans[i]=(*b[d[i]].begin()).id;
b[d[i]].erase(b[d[i]].begin());
} for (int i=;i<n;i++)
if (a[ans[i+]].x<=a[ans[i]].x&&a[ans[i+]].y<=a[ans[i]].y)//这里必须是<=,可能需要想想
{
cout<<"NO";
return ;
} cout<<"YES"<<endl;
for (int i=;i<=n;i++)
cout<<a[ans[i]].x<<" "<<a[ans[i]].y<<endl;
return ;
}

Codeforces Round #331 (Div. 2) C. Wilbur and Points的更多相关文章

  1. Codeforces Round &num;331 &lpar;Div&period; 2&rpar;C&period; Wilbur and Points 贪心

    C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...

  2. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; E&period; Wilbur and Strings dfs乱搞

    E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...

  3. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; D&period; Wilbur and Trees 记忆化搜索

    D. Wilbur and Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  4. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; B&period; Wilbur and Array 水题

    B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  5. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; A&period; Wilbur and Swimming Pool 水题

    A. Wilbur and Swimming Pool Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  6. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; &lowbar;A&period; Wilbur and Swimming Pool

    A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; B&period; Wilbur and Array

    B. Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round &num;331 &lpar;Div&period; 2&rpar;

    水 A - Wilbur and Swimming Pool 自从打完北京区域赛,对矩形有种莫名的恐惧.. #include <bits/stdc++.h> using namespace ...

  9. Codeforces Round &num;331 &lpar;Div&period; 2&rpar; A

    A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. Jenkins 2&period;16&period;3默认没有Launch agent via Java Web Start,如何配置使用

    问题:Jenkins 2.16.3默认没有Launch agent via Java Web Start,如下图所示,而这种启动方式在Windows上是最方便的. 如何设置才能让出来呢? 打开&quo ...

  2. Java Generics and Collections-8&period;1

    8.1 Take Care when Calling Legacy Code 通常,泛型都是在编译时检查的,而不是运行时.便意识检查可以提早通知错误,而不至于到运行时才出问题. 但有时后编译时检查不一 ...

  3. ArcGisEngineForJava开发

    ArcGIS Engine control examples 一.利用Visual JavaBeans来构建应用程序 这种方案是针对使用可视化的Java组件,想要来构建和部署应用程序的开发人员.Jav ...

  4. 接微软技术(c&num;&comma;&period;net&comma;vb&period;net&comma; asp&period;net&comma; sql server&comma; bi&comma; dw etc)项目

    最近闲赋在家,接微软技术的项目,主要有c#,.net,vb.net, asp.net, sql server, bi, dw etc,欢迎推荐.不好意思,借首页发一下.

  5. SSH框架之一详解maven搭建多模块项目

    闲来无事,思量着自己搭建一个ssh框架,一来回顾熟悉一下ssh的内容,hibernate还就没用过了,生疏了都.二来整合一下,将其他掌握的和正在学习的框架核技术糅合到一起,就当是做一个demo练手了. ...

  6. 根据域名获取IP地址&comma;并探测是否可达

    /* Author :decwang@2014.09.01 Mail :deworks@sina.com*/#define PRINTLOG printf//返回0表示成功,其他为失败. int ge ...

  7. ecshop 无限分类解析&lpar;转&rpar;

    对ecshop无限级分类的解析,认真分析后发现真的其算法还是比较精典的其实并不难理解,有举例方便大家理解 function cat_options($spec_cat_id, $arr) { stat ...

  8. HBase的索引

    LSM树由来.设计思想以及应用到HBase的索引   讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎  是哈希表的持久化实现,支持增.删.改以及随机读取操作,但 ...

  9. hadoop2&period;6&period;0实践:引入开发依赖的jar包

    hadoop-2.5.0\share\hadoop\common  所有jar,hadoop-2.5.0\share\hadoop\common\lib  所有jar,hadoop-2.5.0\sha ...

  10. docker 清理容器的命令

    执行以下命令会彻底清除所有容器. docker rm -f $(docker ps -qa) rm -rf /var/lib/etcd /var/lib/cni /var/run/calico rm ...