-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path331C.cpp
More file actions
67 lines (61 loc) · 1.4 KB
/
331C.cpp
File metadata and controls
67 lines (61 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
pair<int,int> arr[100010];
int flag[100010];
int neg[100010];
int fl[100010];
int ng[100010];
//vector<int> ind[100010];
//vector<int> din[100010];
//int flag[100010];
//int neg[100010];
int main(){
int n,s,cnt,x[100010];
while(cin>>n){
for(int i=0;i<n;i++){
scanf("%d%d",&arr[i].first,&arr[i].second);
s=arr[i].second-arr[i].first;
if(s>=0){
fl[s]++;
flag[s]=i;
}
else {
ng[-s]++;
neg[-s]=i;
}
}
cnt=0;
for(int i=0;i<n;i++){
scanf("%d",&x[i]);
if(x[i]>=0){
if(fl[x[i]]){
cnt++;
fl[x[i]]--;
}
}
else{
if(ng[-x[i]]){
cnt++;
ng[-x[i]]--;
}
}
}
if(cnt==n){
printf("YES\n");
for(int i=0;i<n;i++){
if(x[i]>=0){
printf("%d %d\n",arr[flag[x[i]]].first,arr[flag[x[i]]].second);
}
else{
printf("%d %d\n",arr[neg[-x[i]]].first,arr[neg[-x[i]]].second);
}
}
}
else{
printf("NO\n");
}
}
}