-
Notifications
You must be signed in to change notification settings - Fork 3
/
B_Collecting_Packages.cpp
149 lines (131 loc) · 2.64 KB
/
B_Collecting_Packages.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <bits/stdc++.h>
#define ll long long
#define ld long int
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
using namespace std;
// 8""""8
// 8 " eeeee eeeee eeee
// 8e 8 88 8 8 8
// 88 8 8 8e 8 8eee
// 88 e 8 8 88 8 88
// 88eee8 8eee8 88ee8 88ee
// --------MATHS OPERATIONS---------
const int N = 2e5 + 1;
const int MOD = 1e9 + 7;
ll fact[N], inv[N], invfact[N];
void factInverse()
{
fact[0] = inv[1] = fact[1] = invfact[0] = invfact[1] = 1;
for (long long i = 2; i < N; i++)
{
fact[i] = (fact[i - 1] * i) % MOD;
inv[i] = MOD - (inv[MOD % i] * (MOD / i) % MOD);
invfact[i] = (inv[i] * invfact[i - 1]) % MOD;
}
}
int add(int a, int b)
{
if ((a += b) >= MOD)
a -= MOD;
else if (a < 0)
a += MOD;
return a;
}
ll mul(int x, int y)
{
return (1LL * x * y) % MOD;
}
ll nCr(int n, int r)
{
if (r > n)
return 0;
return mul(mul(fact[n], invfact[r]), invfact[n - r]);
}
long long pow(long long base, long long n, long long m = MOD)
{
long long ans = 1ll;
while (n != 0)
{
if (n % 2)
{
ans = (ans * base) % m;
n--;
}
else
{
base = (base * base) % m;
n /= 2;
}
}
return ans;
}
// --------SOLVE---------
bool cmp(pair<int, int> a, pair<int, int> b)
{
if (a.first == b.first)
{
return a.second < b.second;
}
return a.first < b.first;
}
void solve()
{
int n;
cin >> n;
vector<pair<int, int>> arr(n);
for (int i = 0; i < n; i++)
{
cin >> arr[i].first;
cin >> arr[i].second;
}
sort(arr.begin(), arr.end(), cmp);
int x = 0;
int y = 0;
int calc, calc1;
string result = "";
bool possible = true;
for (int i = 0; i < n; i++)
{
// cout << arr[i].first << " " << arr[i].second;
calc = arr[i].first - x;
calc1 = arr[i].second - y;
// cout << " " << calc << " " << calc1 << endl;
if (calc < 0 or calc1 < 0)
{
possible = false;
break;
}
if (calc != 0)
{
result += string(calc, 'R');
}
if (calc1 != 0)
{
result += string(calc1, 'U');
}
x = arr[i].first;
y = arr[i].second;
}
if (possible)
{
cout << "YES" << endl
<< result << endl;
return;
}
cout << "NO" << endl;
}
// --------XXXXXXXXX---------
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}