fork(3) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <stack>
  7. #include <map>
  8. #include <set>
  9. #include <functional>
  10. #include <utility>
  11. #include <climits>
  12. #include <cmath>
  13. #include <cstdio>
  14. #include <cstring>
  15. #include <cstdlib>
  16.  
  17. using namespace std;
  18.  
  19. #define MEM(a, b) memset(a, (b), sizeof(a))
  20. #define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
  21. #define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
  22. #define REP(i, j) FOR(i, 0, j, 1)
  23. #define RREP(i, j) RFOR(i, j, 0, 1)
  24. #define all(cont) cont.begin(), cont.end()
  25. #define rall(cont) cont.end(), cont.begin()
  26. #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
  27. #define IN(A, B, C) ( B <= A && A <= C)
  28. #define MP make_pair
  29. #define PB push_back
  30. #define INF (int)1e9
  31. #define EPS 1e-9
  32. #define PI 3.1415926535897932384626433832795
  33. #define MOD 1000000007
  34. #define read(type) readInt<type>()
  35. #define maX(a,b) ( (a) > (b) ? (a) : (b))
  36. #define miN(a,b) ( (a) < (b) ? (a) : (b))
  37. #define checkBit(n,b) ( (n >> b) & 1)
  38. #define SZ(a) ((unsigned)(a.size()))
  39. #define FI first
  40. #define SE second
  41. #define char2Int(c) (c-'0')
  42. #define ABS(x) (x<0?(-x):x)
  43. #define lowbit(x) ((x)&((x)^((x)-1)))
  44. #define SRT(x) sort(all(x))
  45.  
  46. const double pi=acos(-1.0);
  47. typedef pair<int, int> PII;
  48. typedef vector<int> VI;
  49. typedef vector<string> VS;
  50. typedef vector<PII> VII;
  51. typedef vector<VI> VVI;
  52. typedef map<int,int> MPII;
  53. typedef set<int> SETI;
  54. typedef multiset<int> MSETI;
  55. typedef long int int32;
  56. typedef unsigned long int uint32;
  57. typedef long long int int64;
  58. typedef unsigned long long int uint64;
  59.  
  60. // directions
  61. const int fx[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};
  62. const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
  63. template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
  64. template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOREACH(it, t)s<<*it<<" ";return s; }
  65.  
  66. template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
  67. template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
  68.  
  69. template<typename type>inline type GCD(type a,type b){if(b)while((a%=b)&&(b%=a));return a+b;}
  70. template<typename type>inline type LCM(type a,type b){return a*b/gcd(a,b);}
  71.  
  72. template <typename T> inline void write(T x)
  73. {
  74. int i = 20;
  75. char buf[21];
  76. // buf[10] = 0;
  77. buf[20] = '\n';
  78.  
  79. do
  80. {
  81. buf[--i] = x % 10 + '0';
  82. x/= 10;
  83. }while(x);
  84. do
  85. {
  86. putchar(buf[i]);
  87. } while (buf[i++] != '\n');
  88. }
  89.  
  90. template <typename T> inline T readInt()
  91. {
  92. T n=0,s=1;
  93. char p=getchar();
  94. if(p=='-')
  95. s=-1;
  96. while((p<'0'||p>'9')&&p!=EOF&&p!='-')
  97. p=getchar();
  98. if(p=='-')
  99. s=-1,p=getchar();
  100. while(p>='0'&&p<='9') {
  101. n = (n<< 3) + (n<< 1) + (p - '0');
  102. p=getchar();
  103. }
  104.  
  105. return n*s;
  106. }
  107.  
  108. struct c
  109. {
  110. long long x, y, i;
  111. };
  112. int firstsort(const void* a, const void* b)
  113. {
  114. c* f = (c* )a;
  115. c* s = (c* )b;
  116. return (f->x - s->x);
  117. }
  118.  
  119. int secondsort(const void* a, const void* b)
  120. {
  121. c* f = (c* )a;
  122. c* s = (c* )b;
  123. return (f->i - s->i);
  124. }
  125. int customsort(const void* a, const void* b)
  126. {
  127. c* f = (c* )a;
  128. c* s = (c* )b;
  129. long long d1 = (f->y) - (f->x);
  130. long long d2 = (s->y) - (s->x);
  131. if(d1 != d2)
  132. {
  133. return d1 - d2;
  134. }
  135. else
  136. {
  137. if(f->x < s->x && f->y < s->y)
  138. {
  139. return -1;
  140. }
  141. else if(f->x > s->x && f->y > s->y)
  142. {
  143. return 1;
  144. }
  145. else if(f->x != s->x)
  146. {
  147. return f->x - s->x;
  148. }
  149. else
  150. {
  151. return f->y - s->y;
  152. }
  153. }
  154. }
  155.  
  156. int main()
  157. {
  158. ios::sync_with_stdio(0);
  159. cin.tie(0);
  160. cout.tie(0);
  161. int tc = 1;
  162. //tc = read(int);
  163.  
  164. while(tc--){
  165. long long n;
  166. cin >> n;
  167. c a[n];
  168. for(long long i = 0; i < n; i++)
  169. {
  170. cin >> a[i].x >> a[i].y;
  171. a[i].i = i;
  172. }
  173. c b[n];
  174. for(long long i = 0; i < n; i++)
  175. {
  176. cin >> b[i].x;
  177. b[i].i = i;
  178. }
  179.  
  180. qsort(a, n, sizeof(c), customsort);
  181. qsort(b, n, sizeof(c), firstsort);
  182.  
  183. bool possible = false, eq = false, seq = false;
  184. for(long long i = 0; i < n; i++)
  185. {
  186. if((a[i].y - a[i].x) != b[i].x)
  187. {
  188. cout << "NO" << endl;
  189. return 0;
  190. }
  191. else
  192. {
  193. b[i].y = i;
  194. }
  195. }
  196.  
  197. eq = true;
  198. qsort(b, n, sizeof(c), secondsort);
  199. #if 0
  200. qsort(d, n, sizeof(c), testsort);
  201.  
  202. for(long long i = 0; i < n; i++)
  203. {
  204. if((a[i].y != d[i].x) || a[i].y != d[i].y)
  205. {
  206. cout << "NO" << endl;
  207. return 0;
  208. }
  209. }
  210. #endif
  211. cout << "YES\n";
  212. for(long long i = 0; i < n; i++)
  213. {
  214. cout << a[b[i].y].x << " " << a[b[i].y].y << endl;
  215. }
  216. }
  217. return 0;
  218. }
Success #stdin #stdout 0s 3412KB
stdin
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
stdout
YES
0 0
1 0
2 0
0 1
1 1